Removing old N3 editing code. NIHVIVO-3807

This commit is contained in:
briancaruso 2012-06-21 21:57:45 +00:00
parent f6b2387a3e
commit 56d23c8e2c
42 changed files with 85 additions and 6172 deletions

View file

@ -1,31 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import static org.junit.Assert.*;
import java.util.Collections;
import junit.framework.Assert;
import org.junit.Test;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation;
public class BasicValidationTest {
@Test
public void testValidate() {
BasicValidation bv = new BasicValidation(Collections.EMPTY_MAP);
String res;
res = bv.validate("httpUrl", "http://example.com/index");
Assert.assertEquals(res, bv.SUCCESS);
res = bv.validate("httpUrl", "http://example.com/index?bogus=skjd%20skljd&something=sdkf");
Assert.assertEquals(res, bv.SUCCESS);
res = bv.validate("httpUrl", "http://example.com/index#2.23?bogus=skjd%20skljd&something=sdkf");
Assert.assertEquals(res, bv.SUCCESS);
}
}

View file

@ -1,85 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator;
public class EditN3GeneratorTest {
EditN3Generator en3g ;
@Before
public void setUp() throws Exception {
en3g = new EditN3Generator((EditConfiguration) null);
}
@Test
public void testSubInLiterals() {
String var = "TestVar";
String target = "Fake n3 ?TestVar .";
Literal literal = null;
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
String result = en3g.subInLiterals(var, literal, target);
Assert.assertNotNull( result );
}
@Test
public void testSubInLiteralsWithGroupReference() {
String var = "TestVar";
String target = "Fake n3 ?TestVar .";
Literal literal = new EditLiteral("should not a regex group --> ?2 <-- blblkj (lskdfj) " ,null,null);
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
String result = en3g.subInLiterals(var, literal, target);
Assert.assertNotNull( result );
Assert.assertEquals("Fake n3 \"should not a regex group --> ?2 <-- blblkj (lskdfj) \" ." , result);
}
@Test
public void testConflictingVarNames(){
Map<String,String> varToExisting= new HashMap<String,String>();
varToExisting.put("bob", "http://uri.edu#BobTheElder");
varToExisting.put("bobJr", "http://uri.edu#BobTheSon");
String target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
List<String> targets = new ArrayList<String>();
targets.add(target);
List<String> out = en3g.subInUris(varToExisting, targets);
Assert.assertNotNull(out);
Assert.assertNotNull( out.get(0) );
String expected = "SELECT ?cat WHERE{ <http://uri.edu#BobTheSon> <http://uri.edu#hasCat> ?cat }";
Assert.assertEquals(expected, out.get(0) );
//force a non match on a initial-partial var name
varToExisting= new HashMap<String,String>();
varToExisting.put("bob", "http://uri.edu#BobTheElder");
target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
targets = new ArrayList<String>();
targets.add(target);
out = en3g.subInUris(varToExisting, targets);
Assert.assertNotNull(out);
Assert.assertNotNull( out.get(0) );
expected = target;
Assert.assertEquals(expected, out.get(0) );
}
}

View file

@ -1,75 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import stubs.javax.servlet.http.HttpServletRequestStub;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
public class EditSubmissionTest extends AbstractTestClass {
HttpServletRequestStub request;
EditConfiguration editConfig;
@Before
public void createEditConfig() throws IOException {
InputStream is = this.getClass().getResourceAsStream(
"testEditConfig.json");
editConfig = new EditConfiguration(readAll(is));
}
@Before
public void createRequest() {
request = new HttpServletRequestStub();
request.addParameter("yearfield222", "2001");
request.addParameter("monthfield222", "10");
request.addParameter("dayfield222", "13");
request.addParameter("hourfield222", "11");
request.addParameter("minutefield222", "00");
request.addParameter("talkName", "this is the name of a talk");
request.addParameter("room", "http://someBogusUri/#individual2323");
request.addParameter("editKey", "fakeEditKey");
}
public void testSetup() {
Assert.assertNotNull("EditConfiguration is null", editConfig);
Assert.assertNotNull("request must not be null", request);
}
@Test
public void testDateTimeParameter() {
EditSubmission editSub = new EditSubmission(request.getParameterMap(),
editConfig);
Literal field222 = editSub.getLiteralsFromForm().get("field222");
Assert.assertNotNull(field222);
}
@Test
public void testCanHandleMissingParameter() {
/*
* test if the EditSubmission can be passed a request which is missing a
* parameter. This will be the case when a checkbox type input is not
* selected.
*/
request.removeParameter("talkName");
request.removeParameter("room");
// just trying to make this without an exception
EditSubmission editSub = new EditSubmission(request.getParameterMap(),
editConfig);
Assert.assertNotNull(editSub);
}
}

View file

@ -1,32 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.SparqlEvaluate;
public class SparqlEvaluateTest {
SparqlEvaluate sEval;
@Before
public void setUp() throws Exception {
EditConfiguration edConfig = new EditConfiguration();
Model model = ModelFactory.createDefaultModel(); //just used to parse sparql
sEval = new SparqlEvaluate(model);
}
@Test
public void testForNoSolution() {
String uri = sEval.queryToUri("SELECT ?cat WHERE { ?cat <http://cornell.edu#hasOwner> <http://cornell.edu#bdc34>} ");
Assert.assertNull( uri );
}
}

View file

@ -1,89 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import java.io.StringReader;
public class EditN3GeneratorTest {
EditN3Generator en3g ;
@Before
public void setUp() throws Exception {
en3g = new EditN3Generator((EditConfiguration) null);
}
@Test
public void testSubInLiterals() {
String var = "TestVar";
String target = "Fake n3 ?TestVar .";
Literal literal = null;
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
String result = en3g.subInLiterals(var, literal, target);
Assert.assertNotNull( result );
}
@Test
public void testSubInLiteralsWithGroupReference() {
String var = "TestVar";
String target = "Fake n3 ?TestVar .";
Literal literal = new EditLiteral("should not a regex group --> ?2 <-- blblkj (lskdfj) " ,null,null);
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
String result = en3g.subInLiterals(var, literal, target);
Assert.assertNotNull( result );
Assert.assertEquals("Fake n3 \"should not a regex group --> ?2 <-- blblkj (lskdfj) \" ." , result);
}
@Test
public void testConflictingVarNames(){
Map<String,String> varToExisting= new HashMap<String,String>();
varToExisting.put("bob", "http://uri.edu#BobTheElder");
varToExisting.put("bobJr", "http://uri.edu#BobTheSon");
String target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
List<String> targets = new ArrayList<String>();
targets.add(target);
List<String> out = en3g.subInUris(varToExisting, targets);
Assert.assertNotNull(out);
Assert.assertNotNull( out.get(0) );
String expected = "SELECT ?cat WHERE{ <http://uri.edu#BobTheSon> <http://uri.edu#hasCat> ?cat }";
Assert.assertEquals(expected, out.get(0) );
//force a non match on a initial-partial var name
varToExisting= new HashMap<String,String>();
varToExisting.put("bob", "http://uri.edu#BobTheElder");
target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
targets = new ArrayList<String>();
targets.add(target);
out = en3g.subInUris(varToExisting, targets);
Assert.assertNotNull(out);
Assert.assertNotNull( out.get(0) );
expected = target;
Assert.assertEquals(expected, out.get(0) );
}
}