use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.
the class FulltextIndexChangeListenerTest method onCreateHandlesWwDocumentsUsingCustomLogic.
@Test
public void onCreateHandlesWwDocumentsUsingCustomLogic() {
IndexHandler indexHandler = mock(IndexHandler.class);
GraphWrapper graphWrapper = newGraph().withVertex("doc", v -> v.withProperty("wwdocument_name", "foo").withOutgoingRelation("isCreatedBy", "authorA", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withOutgoingRelation("isCreatedBy", "authorB", r -> r.withAccepted("wwrelation", true).withIsLatest(true))).withVertex("authorA", v -> v.withProperty("wwperson_name", "authorA")).withVertex("authorB", v -> v.withProperty("wwperson_name", "authorB")).wrap();
FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
Collection collection = new VresBuilder().withVre("womenwriters", "ww", vre -> vre.withCollection("wwdocuments", coll -> coll.withDisplayName(localProperty("wwdocument_name"))).withCollection("wwpersons", coll -> coll.withDisplayName(localProperty("wwperson_name")))).build().getCollection("wwdocuments").get();
Vertex vertex = graphWrapper.getGraph().traversal().V().next();
instance.onCreate(collection, vertex);
verify(indexHandler).upsertIntoQuickSearchIndex(collection, "authorA; authorB foo", vertex, null);
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.
the class IdIndexChangeListenerTest method onCreateAddsTheVertexToTheIdIndex.
@Test
public void onCreateAddsTheVertexToTheIdIndex() {
UUID timId = UUID.randomUUID();
Vertex vertex = vertexWithId(timId);
IndexHandler indexHandler = mock(IndexHandler.class);
IdIndexChangeListener instance = new IdIndexChangeListener(indexHandler);
instance.onCreate(NULL_COLLECTION, vertex);
verify(indexHandler).upsertIntoIdIndex(timId, vertex);
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.
the class Neo4jLuceneEntityFetcherTest method getEntityRetrievesTheLatestFromTheGraphEvenIfTheIndexIsNotUpToDate.
@Test
public void getEntityRetrievesTheLatestFromTheGraphEvenIfTheIndexIsNotUpToDate() {
final UUID timId = UUID.randomUUID();
final String collectionName = "things";
TinkerPopGraphManager graphManager = newGraph().withVertex("latest", v -> v.withTimId(timId).isLatest(true)).withVertex(v -> v.withTimId(timId).isLatest(false).withOutgoingRelation("VERSION_OF", "latest")).wrap();
GraphTraversal<Vertex, Vertex> secondLatestVertexT = graphManager.getGraph().traversal().V().has("tim_id", timId.toString()).has("isLatest", false);
given(indexHandler.findById(timId)).willReturn(Optional.of(secondLatestVertexT.next()));
Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler);
GraphTraversalSource traversal = graphManager.getGraph().traversal();
GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, collectionName);
assertThat(entityT.hasNext(), is(true));
assertThat(entityT.next(), is(likeVertex().withTimId(timId).withProperty("isLatest", true)));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.
the class Neo4jLuceneEntityFetcherTest method getEntityRetrievesTheVertexDirectFromTheDatabaseWhenTheIndexDoesNotContainIt.
@Test
public void getEntityRetrievesTheVertexDirectFromTheDatabaseWhenTheIndexDoesNotContainIt() {
final UUID timId = UUID.randomUUID();
final String things = "things";
TinkerPopGraphManager graphManager = newGraph().withVertex("latest", v -> v.withTimId(timId).isLatest(true)).withVertex(v -> v.withTimId(timId).isLatest(false).withOutgoingRelation("VERSION_OF", "latest")).wrap();
given(indexHandler.findById(timId)).willReturn(Optional.empty());
Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler);
GraphTraversalSource traversal = graphManager.getGraph().traversal();
GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, things);
assertThat(entityT.next().value("tim_id"), equalTo(timId.toString()));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler 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);
}
Aggregations