Search in sources :

Example 1 with Neo4jLuceneEntityFetcher

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher 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)));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test)

Example 2 with Neo4jLuceneEntityFetcher

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher 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()));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test)

Aggregations

Optional (java.util.Optional)2 UUID (java.util.UUID)2 IndexHandler (nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler)2 Neo4jLuceneEntityFetcher (nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher)2 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)2 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)2 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Before (org.junit.Before)2 Test (org.junit.Test)2 BDDMockito.given (org.mockito.BDDMockito.given)2 Mockito.mock (org.mockito.Mockito.mock)2