-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced PlainGraph with GraphMem as a workaround for Jena plain grap…
…h serialization bug.
- Loading branch information
Showing
5 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...a/edu/cornell/mannlib/vitro/webapp/rdfservice/adapters/AbstractBulkUpdatingModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters; | ||
|
||
import org.apache.jena.graph.Graph; | ||
import org.apache.jena.rdf.model.Literal; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.ResourceFactory; | ||
import org.apache.jena.rdf.model.impl.PropertyImpl; | ||
import org.apache.jena.rdf.model.impl.ResourceImpl; | ||
import org.apache.jena.rdf.model.impl.StatementImpl; | ||
|
||
public class AbstractBulkUpdatingModelTest { | ||
|
||
public AbstractBulkUpdatingModelTest() { | ||
super(); | ||
} | ||
|
||
protected StatementImpl getStatement() { | ||
ResourceImpl subject = new ResourceImpl("test:uri1"); | ||
PropertyImpl property = new PropertyImpl("http://www.w3.org/2000/01/rdf-schema#label"); | ||
Literal object = ResourceFactory.createLangLiteral("Persons", "en-US"); | ||
StatementImpl statement = new StatementImpl(subject, property, object); | ||
return statement; | ||
} | ||
|
||
static class WrappedUpdater extends AbstractBulkUpdater { | ||
|
||
private AbstractBulkUpdater wrappedUpdater; | ||
|
||
public void add(Graph g) { | ||
performAddModel(ModelFactory.createModelForGraph(g)); | ||
} | ||
|
||
public WrappedUpdater(AbstractBulkUpdater updater) { | ||
this.wrappedUpdater = updater; | ||
} | ||
|
||
@Override | ||
protected void performAddModel(Model model) { | ||
wrappedUpdater.performAddModel(model); | ||
} | ||
|
||
@Override | ||
protected void performRemoveModel(Model model) { | ||
wrappedUpdater.performRemoveModel(model); | ||
} | ||
|
||
@Override | ||
protected void performRemoveAll() { | ||
wrappedUpdater.performRemoveAll(); | ||
} | ||
} | ||
|
||
} | ||
|
64 changes: 64 additions & 0 deletions
64
...test/java/edu/cornell/mannlib/vitro/webapp/rdfservice/adapters/BulkUpdatingModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters; | ||
|
||
import java.util.Arrays; | ||
|
||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Statement; | ||
import org.junit.Test; | ||
|
||
public class BulkUpdatingModelTest extends AbstractBulkUpdatingModelTest { | ||
|
||
@Test | ||
public void testRemoveWithIterator() { | ||
BulkUpdatingModel wrappedModel = getWrappedModel(); | ||
Model removeModel = VitroModelFactory.createModel(); | ||
removeModel.add(getStatement()); | ||
wrappedModel.remove(removeModel.listStatements()); | ||
} | ||
|
||
@Test | ||
public void testRemoveStatementArray() { | ||
BulkUpdatingModel wrapModel = getWrappedModel(); | ||
wrapModel.remove(new Statement[] { getStatement() }); | ||
} | ||
|
||
@Test | ||
public void testRemoveStatementList() { | ||
BulkUpdatingModel wrapModel = getWrappedModel(); | ||
wrapModel.remove(Arrays.asList(getStatement())); | ||
} | ||
|
||
@Test | ||
public void testAddWithIterator() { | ||
BulkUpdatingModel wrappedModel = getWrappedModel(); | ||
Model model = VitroModelFactory.createModel(); | ||
model.add(getStatement()); | ||
wrappedModel.add(model.listStatements()); | ||
} | ||
|
||
@Test | ||
public void testAddStatementArray() { | ||
BulkUpdatingModel wrapModel = getWrappedModel(); | ||
wrapModel.add(new Statement[] { getStatement() }); | ||
} | ||
|
||
@Test | ||
public void testAddStatementList() { | ||
BulkUpdatingModel wrapModel = getWrappedModel(); | ||
wrapModel.add(Arrays.asList(getStatement())); | ||
} | ||
|
||
private BulkUpdatingModel getWrappedModel() { | ||
Model m = ModelFactory.createDefaultModel(); | ||
RDFService rdfService = new RDFServiceModel(m); | ||
RDFServiceGraph g = new RDFServiceGraph(rdfService); | ||
BulkUpdatingModel wrappedModel = new BulkUpdatingModel(RDFServiceGraph.createRDFServiceModel(g)); | ||
wrappedModel.updater = new WrappedUpdater(wrappedModel.updater); | ||
return wrappedModel; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...t/java/edu/cornell/mannlib/vitro/webapp/rdfservice/adapters/BulkUpdatingOntModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters; | ||
|
||
import static org.apache.jena.ontology.OntModelSpec.OWL_MEM; | ||
|
||
import java.util.Arrays; | ||
|
||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; | ||
import org.apache.jena.ontology.OntModel; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Statement; | ||
import org.junit.Test; | ||
|
||
public class BulkUpdatingOntModelTest extends AbstractBulkUpdatingModelTest { | ||
|
||
@Test | ||
public void testRemoveWithIterator() { | ||
OntModel wrappedModel = getWrappedModel(); | ||
Model removeModel = VitroModelFactory.createModel(); | ||
removeModel.add(getStatement()); | ||
wrappedModel.remove(removeModel.listStatements()); | ||
} | ||
|
||
@Test | ||
public void testRemoveStatementArray() { | ||
OntModel wrapModel = getWrappedModel(); | ||
wrapModel.remove(new Statement[] { getStatement() }); | ||
} | ||
|
||
@Test | ||
public void testRemoveStatementList() { | ||
OntModel wrapModel = getWrappedModel(); | ||
wrapModel.remove(Arrays.asList(getStatement())); | ||
} | ||
|
||
@Test | ||
public void testAddWithIterator() { | ||
OntModel wrappedModel = getWrappedModel(); | ||
Model model = VitroModelFactory.createModel(); | ||
model.add(getStatement()); | ||
wrappedModel.add(model.listStatements()); | ||
} | ||
|
||
@Test | ||
public void testAddStatementArray() { | ||
OntModel wrapModel = getWrappedModel(); | ||
wrapModel.add(new Statement[] { getStatement() }); | ||
} | ||
|
||
@Test | ||
public void testAddStatementList() { | ||
OntModel wrapModel = getWrappedModel(); | ||
wrapModel.add(Arrays.asList(getStatement())); | ||
} | ||
|
||
private OntModel getWrappedModel() { | ||
Model m = ModelFactory.createOntologyModel(); | ||
RDFService rdfService = new RDFServiceModel(m); | ||
RDFServiceGraph g = new RDFServiceGraph(rdfService); | ||
|
||
Model bareModel = new BulkModelCom(g); | ||
OntModel ontModel = new BulkOntModelImpl(OWL_MEM, bareModel); | ||
BulkUpdatingOntModel wrappedModel = new BulkUpdatingOntModel(ontModel); | ||
wrappedModel.updater = new WrappedUpdater(wrappedModel.updater); | ||
return wrappedModel; | ||
} | ||
|
||
} |