Skip to content

Commit

Permalink
test added
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed May 26, 2023
1 parent cf3cc28 commit 1e19238
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void addWithoutNotify(Triple t) {
performAdd(t);
}

public final void deleteWithoutNotify(Triple t) {
public void deleteWithoutNotify(Triple t) {
checkOpen();
performDelete(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import java.util.List;

import org.junit.Test;

import org.apache.jena.graph.Triple;
import org.apache.jena.graph.impl.GraphWithPerform;
import org.apache.jena.mem.GraphMem;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.impl.OntModelImpl;
import org.apache.jena.rdf.listeners.StatementListener;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
Expand All @@ -27,6 +28,8 @@
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.impl.ModelCom;
import org.apache.jena.shared.Lock;

import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.testing.RecordingProxy;
Expand Down Expand Up @@ -65,6 +68,9 @@
* presumably the bulk updaters will be removed completely.
*/
public class VitroModelFactoryTest extends AbstractTestClass {

private String testData = "src/test/resources/edu/cornell/mannlib/vitro/webapp/rdfservice/adapters/vitro_model_factory_test_data.n3";

private static final Statement SINGLE_STATEMENT = stmt(
resource("http://subject"), property("http://add"),
literal("object"));
Expand Down Expand Up @@ -463,7 +469,49 @@ public void addMultipleToVitroOntUnion() {
.test();
}

// ----------------------------------------------------------------------
@Test
public void testCreateNewBulkOntModel() {
TestBulkGraphMem spyGraph = new TestBulkGraphMem();
Model baseModel = new ModelCom(spyGraph);
OntModel intermediateOntModel = new OntModelImpl(OWL_MEM, baseModel);
OntModel ontModel = VitroModelFactory.createOntologyModel(intermediateOntModel);
Model inputModel = ModelFactory.createDefaultModel();
try {
inputModel.enterCriticalSection(Lock.WRITE);
inputModel.read(testData);
} finally {
inputModel.leaveCriticalSection();
}
assertEquals(0, spyGraph.countAddWithoutNotify);
assertEquals(0, spyGraph.countDeleteWithoutNotify);
ontModel.add(inputModel);
assertEquals(5, spyGraph.countAddWithoutNotify);
assertEquals(0, spyGraph.countDeleteWithoutNotify);

ontModel.remove(inputModel);
assertEquals(5, spyGraph.countAddWithoutNotify);
assertEquals(5, spyGraph.countDeleteWithoutNotify);
}

private static class TestBulkGraphMem extends BulkGraphMem {
int countDeleteWithoutNotify = 0;
int countAddWithoutNotify = 0;

@Override
public void addWithoutNotify(Triple t) {
checkOpen();
performAdd(t);
countAddWithoutNotify++;
}
@Override
public final void deleteWithoutNotify(Triple t) {
checkOpen();
performDelete(t);
countDeleteWithoutNotify++;
}
}

// ----------------------------------------------------------------------
// OntModel of Union of Models
//
// This shouldn't hold any surprises, should it?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<test:bob> <test:has_publication> <test:bob_publication1> .
<test:bob> <test:has_publication> <test:bob_publication2> .
<test:bob> <test:has_publication> <test:bob_publication3> .
<test:alice> <test:has_publication> <test:alice_publication1> .
<test:alice> <test:has_publication> <test:alice_publication2> .

0 comments on commit 1e19238

Please sign in to comment.