Fixing NewIndivdiual form generator and adding unit tests for ProcessRdfForm and EditN3Generator
This commit is contained in:
parent
6b9324119e
commit
ff8c14a725
8 changed files with 135 additions and 71 deletions
|
@ -21,6 +21,12 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|||
public class EditN3GeneratorVTwoTest {
|
||||
static EditN3GeneratorVTwo gen = new EditN3GeneratorVTwo();
|
||||
|
||||
@Test
|
||||
public void testVarAtEndOfString(){
|
||||
String result = gen.subInNonBracketedURIS("newRes", "<http://someuri.com/n23", "?newRes");
|
||||
Assert.assertEquals("<http://someuri.com/n23", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTarget(){
|
||||
List<String> targets = Arrays.asList("?var",null,null,"?var");
|
||||
|
|
|
@ -197,6 +197,55 @@ public class ProcessRdfFormTest extends AbstractTestClass{
|
|||
ResourceFactory.createResource(test3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicNewResourceTest() throws Exception{
|
||||
/* A very basic new statement edit. */
|
||||
EditConfigurationVTwo config = new EditConfigurationVTwo();
|
||||
config.setEditKey("mockEditKey");
|
||||
config.setN3Required(Arrays.asList("?newRes ?test2 ?test3 ." ));
|
||||
config.setUrisOnform(Arrays.asList( "test2", "test3"));
|
||||
config.addNewResource("newRes", null);
|
||||
config.setEntityToReturnTo("?newRes");
|
||||
|
||||
Map<String,String[]> values = new HashMap<String, String[]>();
|
||||
|
||||
values.put("test2", (new String[] {"http://test.com/uri2"}));
|
||||
values.put("test3", (new String[] {"http://test.com/uri3"}));
|
||||
values.put("editKey", (new String[] {"mockEditKey"}));
|
||||
|
||||
MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config);
|
||||
|
||||
ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker());
|
||||
|
||||
/* test just the N3 substitution part */
|
||||
List<String>req = config.getN3Required();
|
||||
List<String>opt = config.getN3Optional();
|
||||
processor.subInValuesToN3( config , submission, req, opt, null , null);
|
||||
assertNotNull(req);
|
||||
assertTrue( req.size() > 0);
|
||||
assertNotNull(req.get(0));
|
||||
assertEquals("<"+NEWURI_STRING + "0> <http://test.com/uri2> <http://test.com/uri3> .", req.get(0));
|
||||
|
||||
assertEquals("<" + NEWURI_STRING + "0>", submission.getEntityToReturnTo());
|
||||
|
||||
/* test the N3 and parse RDF parts */
|
||||
AdditionsAndRetractions changes = processor.process( config, submission );
|
||||
|
||||
assertNotNull( changes );
|
||||
assertNotNull( changes.getAdditions() );
|
||||
assertNotNull( changes.getRetractions());
|
||||
assertTrue( changes.getAdditions().size() == 1 );
|
||||
assertTrue( changes.getRetractions().size() == 0 );
|
||||
|
||||
assertTrue( changes.getAdditions().contains(
|
||||
ResourceFactory.createResource(NEWURI_STRING + "0"),
|
||||
ResourceFactory.createProperty("http://test.com/uri2"),
|
||||
ResourceFactory.createResource("http://test.com/uri3")));
|
||||
}
|
||||
|
||||
|
||||
String NEWURI_STRING= "http://newURI/n";
|
||||
|
||||
public NewURIMaker getMockNewURIMaker(){
|
||||
return new NewURIMaker() {
|
||||
int count = 0;
|
||||
|
@ -205,7 +254,7 @@ public class ProcessRdfFormTest extends AbstractTestClass{
|
|||
if( prefixURI != null )
|
||||
return prefixURI + count;
|
||||
else
|
||||
return "http://newURI/n" + count;
|
||||
return NEWURI_STRING + count;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue