Search in sources :

Example 41 with TinkerPopGraphManager

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));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 42 with TinkerPopGraphManager

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));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Test(org.junit.Test)

Example 43 with TinkerPopGraphManager

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())));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 44 with TinkerPopGraphManager

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())));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 45 with TinkerPopGraphManager

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));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TransactionEnforcer(nl.knaw.huygens.timbuctoo.core.TransactionEnforcer) ScaffoldMigrator(nl.knaw.huygens.timbuctoo.server.databasemigration.ScaffoldMigrator) Test(org.junit.Test)

Aggregations

TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)137 Test (org.junit.Test)135 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)93 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)91 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)91 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)90 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)90 Optional (java.util.Optional)89 Mockito.mock (org.mockito.Mockito.mock)89 Matchers.is (org.hamcrest.Matchers.is)87 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)84 Edge (org.apache.tinkerpop.gremlin.structure.Edge)84 Matchers.not (org.hamcrest.Matchers.not)84 Mockito.when (org.mockito.Mockito.when)84 UUID (java.util.UUID)83 VreStubs.minimalCorrectVre (nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre)77 QuickSearch (nl.knaw.huygens.timbuctoo.core.dto.QuickSearch)73 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)73 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)73 Matchers.empty (org.hamcrest.Matchers.empty)73