use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class CollectionTest method removeDoesNothingWhenTheEntityIsNotPartOfTheCollection.
@Test
public void removeDoesNothingWhenTheEntityIsNotPartOfTheCollection() {
GraphWrapper graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex("entityNode", v -> {
}).withVertex("entity", v -> v.withLabel("entity")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).next();
Vertex entityVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("entity")).next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper);
try {
instance.remove(entityVertex);
} catch (FastNoSuchElementException e) {
fail("Should not throw an exception.");
}
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class CollectionTest method removeRemovesEdgeBetweenTheVertexAndTheCollection.
@Test
public void removeRemovesEdgeBetweenTheVertexAndTheCollection() {
GraphWrapper graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withLabel("entity")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("collection")).next();
Vertex entityVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("entity")).next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper, mock(CollectionDescription.class), mock(PropertyHelper.class));
instance.remove(entityVertex);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_ENTITY_NODE_RELATION_NAME).out(HAS_ENTITY_RELATION_NAME).hasId(entityVertex.id()).hasNext(), is(false));
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class FulltextIndexChangeListenerTest method doesNotThrowWhenDisplayNameTraversalYieldsNoResults.
@Test
public void doesNotThrowWhenDisplayNameTraversalYieldsNoResults() {
final String theMissingPropertyName = "missingProperty_name";
IndexHandler indexHandler = mock(IndexHandler.class);
GraphWrapper graphWrapper = newGraph().withVertex("newVertex", v -> v.withProperty("locateMe", "here")).wrap();
FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty(theMissingPropertyName)))).build().getCollection("vrecolls").get();
Vertex newVertex = graphWrapper.getGraph().traversal().V().has("locateMe", "here").next();
instance.onAddToCollection(collection, Optional.empty(), newVertex);
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class FulltextIndexChangeListenerTest method onPropertyUpdateRemovesTheOldVertexFromTheIndexBeforeAddingTheNewOne.
@Test
public void onPropertyUpdateRemovesTheOldVertexFromTheIndexBeforeAddingTheNewOne() {
IndexHandler indexHandler = mock(IndexHandler.class);
GraphWrapper graphWrapper = newGraph().withVertex("newVertex", v -> v.withProperty("vrecoll_name", "new")).withVertex(v -> v.withProperty("vrecoll_name", "old").withOutgoingRelation("VERSION_OF", "newVertex")).wrap();
FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty("vrecoll_name")))).build().getCollection("vrecolls").get();
Vertex oldVertex = graphWrapper.getGraph().traversal().V().has("vrecoll_name", "old").next();
Vertex newVertex = graphWrapper.getGraph().traversal().V().has("vrecoll_name", "new").next();
instance.onPropertyUpdate(collection, Optional.of(oldVertex), newVertex);
verify(indexHandler).upsertIntoQuickSearchIndex(collection, "new", newVertex, oldVertex);
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class FulltextIndexChangeListenerTest method onCreateAddsItemsToTheIndexOfTheProvidedCollection.
@Test
public void onCreateAddsItemsToTheIndexOfTheProvidedCollection() {
IndexHandler indexHandler = mock(IndexHandler.class);
GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withProperty("vrecoll_name", "foo")).wrap();
FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty("vrecoll_name")))).build().getCollection("vrecolls").get();
Vertex vertex = graphWrapper.getGraph().traversal().V().next();
instance.onCreate(collection, vertex);
verify(indexHandler).upsertIntoQuickSearchIndex(collection, "foo", vertex, null);
}
Aggregations