use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method hasQuickSearchForReturnsFalseIfTheIndexDoesNotExist.
@Test
public void hasQuickSearchForReturnsFalseIfTheIndexDoesNotExist() {
TinkerPopGraphManager tinkerPopGraphManager = newGraph().wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
Collection collectionWithoutIndex = mock(Collection.class);
when(collectionWithoutIndex.getCollectionName()).thenReturn(COLLECTION);
boolean existingIndex = instance.hasQuickSearchIndexFor(collectionWithoutIndex);
assertThat(existingIndex, is(false));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findByQuickSearchIsCaseInsensitive.
@Test
public void findByQuickSearchIsCaseInsensitive() {
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
String id3 = UUID.randomUUID().toString();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("displayName", "query")).withVertex(v -> v.withTimId(id2).withProperty("displayName", "QUERY2")).withVertex(v -> v.withTimId(id3).withProperty("displayName", "notmatching")).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
QuickSearch quickSearch = QuickSearch.fromQueryString("query*");
GraphTraversal<Vertex, Vertex> vertices = instance.findByQuickSearch(collection, quickSearch);
assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), containsInAnyOrder(id1, id2));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findEdgeByIdReturnsTheEdgeWithId.
// =====================tim_id edge index=====================
@Test
public void findEdgeByIdReturnsTheEdgeWithId() {
UUID edgeId = UUID.randomUUID();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withOutgoingRelation("rel", "other", e -> e.withTim_id(edgeId))).withVertex("other", v -> {
}).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
Edge edge = tinkerPopGraphManager.getGraph().traversal().E().has("tim_id", edgeId.toString()).next();
instance.upsertIntoEdgeIdIndex(edgeId, edge);
Optional<Edge> edgeOpt = instance.findEdgeById(edgeId);
assertThat(edgeOpt, is(present()));
assertThat(edgeOpt.get(), is(likeEdge().withId(edgeId.toString())));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findEdgeByIdReturnsAnEmtptyOptionalWhenTheEdgeIsNotFound.
@Test
public void findEdgeByIdReturnsAnEmtptyOptionalWhenTheEdgeIsNotFound() {
UUID edgeId = UUID.randomUUID();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withOutgoingRelation("rel", "other", e -> e.withTim_id(edgeId))).withVertex("other", v -> {
}).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
Edge edge = tinkerPopGraphManager.getGraph().traversal().E().has("tim_id", edgeId.toString()).next();
instance.upsertIntoEdgeIdIndex(edgeId, edge);
UUID otherEdgeId = UUID.randomUUID();
Optional<Edge> edgeOpt = instance.findEdgeById(otherEdgeId);
assertThat(edgeOpt, is(not(present())));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseRdfIndexTest method indexTest.
@Test
public void indexTest() throws Exception {
final TinkerPopGraphManager mgr = newGraph().wrap();
final Database database = new Database(mgr);
TransactionEnforcer transactionEnforcer = forGraphWrapper(mgr);
new ScaffoldMigrator(mgr).execute();
transactionEnforcer.execute(timbuctooActions -> {
timbuctooActions.ensureVreExists("myVre");
return commit();
});
mgr.getGraph().tx().onClose(x -> assertThat("Transaction should not be closed to be able to verify this unittest. It's okay that you close " + "a transaction during findOrCreateEntity, but you should find another way to verify that findOrCreateIndex " + "can find nodes in the index before a commit was called.", false));
database.findOrCreateEntity("myVre", NodeFactory.createURI("http://example.org/test"));
// Index is created
assertThat(mgr.getGraphDatabase().index().existsForNodes(RDFINDEX_NAME), is(true));
// The nodes is available
assertThat(mgr.getGraphDatabase().index().forNodes(RDFINDEX_NAME).get("myVre", "http://example.org/test").size(), is(1));
}
Aggregations