Search in sources :

Example 26 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class DatabaseFixerTest method fixAddsMissingVertices.

@Test
public void fixAddsMissingVertices() {
    String vertex1CreatedProp = changeStringWithTimestamp(1500L);
    String vertex2CreatedProp = changeStringWithTimestamp(1400L);
    GraphWrapper graphWrapper = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty("rev", 2).withProperty("modified", changeStringWithTimestamp(10000L)).withProperty("created", vertex1CreatedProp).withProperty("isLatest", true)).withVertex("v2", v -> v.withTimId("id2").withProperty("rev", 3).withProperty("modified", changeStringWithTimestamp(10000L)).withProperty("created", vertex2CreatedProp).withProperty("isLatest", true)).wrap();
    DatabaseFixer instance = new DatabaseFixer(graphWrapper);
    instance.fix();
    assertThat(graphWrapper.getGraph().traversal().V().has("tim_id", "id1").toList(), containsInAnyOrder(likeVertex().withTimId("id1").withProperty("rev", 1).withProperty("modified", vertex1CreatedProp), likeVertex().withTimId("id1").withProperty("rev", 2)));
    assertThat(graphWrapper.getGraph().traversal().V().has("tim_id", "id2").toList(), containsInAnyOrder(likeVertex().withTimId("id2").withProperty("rev", 1).withProperty("modified", vertex2CreatedProp), likeVertex().withTimId("id2").withProperty("rev", 2).withProperty("modified", vertex2CreatedProp), likeVertex().withTimId("id2").withProperty("rev", 3)));
}
Also used : ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Iterator(java.util.Iterator) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Direction(org.apache.tinkerpop.gremlin.structure.Direction) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Is.is(org.hamcrest.core.Is.is) Optional(java.util.Optional) Change(nl.knaw.huygens.timbuctoo.model.Change) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Test(org.junit.Test)

Example 27 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class DatabaseFixerTest method fixAddsMissingEdges.

@Test
public void fixAddsMissingEdges() {
    UUID rel1Id = UUID.fromString("ff65089c-2ded-4af0-95e7-0476979f96b8");
    UUID rel2Id = UUID.fromString("a628b090-ec7f-4608-9356-61728355ad5a");
    GraphWrapper wrapper = newGraph().withVertex("v1", v -> v.withTimId("id1")).withVertex("v2", v -> v.withTimId("id2").withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(rel1Id).withRev(2).withIsLatest(true).withModified(changeWithTimestamp(10000L)).withCreated(changeWithTimestamp(1500L)))).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation("relatedTo", "v2", r -> r.withTim_id(rel2Id).withRev(4).withIsLatest(true).withModified(changeWithTimestamp(10000L)).withCreated(changeWithTimestamp(1000L)))).wrap();
    DatabaseFixer databaseFixer = new DatabaseFixer(wrapper);
    databaseFixer.fix();
    assertThat(wrapper.getGraph().traversal().E().has("tim_id", rel1Id.toString()).toList(), containsInAnyOrder(likeEdge().withId(rel1Id.toString()).withProperty("rev", 1).withModifiedTimestamp(1500L), likeEdge().withId(rel1Id.toString()).withProperty("rev", 2).withModifiedTimestamp(10000L)));
    assertThat(wrapper.getGraph().traversal().E().has("tim_id", rel2Id.toString()).toList(), containsInAnyOrder(likeEdge().withId(rel2Id.toString()).withProperty("rev", 1).withModifiedTimestamp(1000L), likeEdge().withId(rel2Id.toString()).withProperty("rev", 2).withModifiedTimestamp(1000L), likeEdge().withId(rel2Id.toString()).withProperty("rev", 3).withModifiedTimestamp(1000L), likeEdge().withId(rel2Id.toString()).withProperty("rev", 4).withModifiedTimestamp(10000L)));
}
Also used : ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Iterator(java.util.Iterator) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Direction(org.apache.tinkerpop.gremlin.structure.Direction) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Is.is(org.hamcrest.core.Is.is) Optional(java.util.Optional) Change(nl.knaw.huygens.timbuctoo.model.Change) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class DatabaseFixerTest method fixAddsAVersionOfRelation.

@Test
public void fixAddsAVersionOfRelation() {
    String vertex1CreatedProp = changeStringWithTimestamp(1500L);
    GraphWrapper graphWrapper = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty("rev", 2).withProperty("modified", changeStringWithTimestamp(10000L)).withProperty("created", vertex1CreatedProp).withProperty("isLatest", true)).wrap();
    DatabaseFixer instance = new DatabaseFixer(graphWrapper);
    instance.fix();
    Optional<Vertex> vertex = graphWrapper.getGraph().traversal().V().has("tim_id", "id1").has("rev", 1).tryNext();
    assertThat(vertex, is(present()));
    Iterator<Edge> versionOfRelations = vertex.get().edges(Direction.OUT, "VERSION_OF");
    assertThat(versionOfRelations.hasNext(), is(true));
}
Also used : ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Iterator(java.util.Iterator) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Direction(org.apache.tinkerpop.gremlin.structure.Direction) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Is.is(org.hamcrest.core.Is.is) Optional(java.util.Optional) Change(nl.knaw.huygens.timbuctoo.model.Change) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 29 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class DatabaseLogTest method generateAppendsEachVersionOfAnEdgeOnlyOnce.

@Test
public void generateAppendsEachVersionOfAnEdgeOnlyOnce() {
    UUID relId = UUID.fromString("ff65089c-2ded-4af0-95e7-0476979f96b8");
    GraphWrapper graphWrapper = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty("modified", getChangeStringWithTimestamp(1464346423L)).withProperty("rev", 3)).withVertex("v2", v -> v.withTimId("id2").withProperty("modified", getChangeStringWithTimestamp(1464346425L)).withProperty("rev", 3).withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(1).withModified(changeWithTimestamp(1464346426L))).withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(2).withModified(changeWithTimestamp(1464346428L))).withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(2).withModified(changeWithTimestamp(1464346428L)))).wrap();
    DatabaseLog instance = createInstance(graphWrapper);
    instance.generate();
    verify(logEntryFactory).createForEdge(argThat(likeEdge().withId(relId.toString()).withProperty("rev", 1)));
    verify(logEntryFactory, times(1)).createForEdge(argThat(likeEdge().withId(relId.toString()).withProperty("rev", 2)));
}
Also used : LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) InOrder(org.mockito.InOrder) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.verify(org.mockito.Mockito.verify) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) BDDMockito.given(org.mockito.BDDMockito.given) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Mockito.inOrder(org.mockito.Mockito.inOrder) Change(nl.knaw.huygens.timbuctoo.model.Change) 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) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) UUID(java.util.UUID) Test(org.junit.Test)

Example 30 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class DatabaseLogTest method generateAppendsAVertexEntryForEachVertexToTheLog.

@Test
public void generateAppendsAVertexEntryForEachVertexToTheLog() throws Exception {
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withTimId("id1").withProperty("modified", getChangeStringWithTimestamp(1464346423L)).withProperty("rev", 1)).withVertex(v -> v.withTimId("id2").withProperty("modified", getChangeStringWithTimestamp(1464346425L)).withProperty("rev", 1)).withVertex(v -> v.withTimId("id3").withProperty("modified", getChangeStringWithTimestamp(1464346424L)).withProperty("rev", 1)).wrap();
    DatabaseLog instance = createInstance(graphWrapper);
    instance.generate();
    verify(vertexLogEntry, times(3)).appendToLog(any(LogOutput.class));
}
Also used : LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) InOrder(org.mockito.InOrder) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.verify(org.mockito.Mockito.verify) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) BDDMockito.given(org.mockito.BDDMockito.given) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Mockito.inOrder(org.mockito.Mockito.inOrder) Change(nl.knaw.huygens.timbuctoo.model.Change) 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) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Test(org.junit.Test)

Aggregations

GraphWrapper (nl.knaw.huygens.timbuctoo.server.GraphWrapper)31 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)31 Test (org.junit.Test)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)28 Mockito.mock (org.mockito.Mockito.mock)25 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)24 Mockito.verify (org.mockito.Mockito.verify)23 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)22 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)20 MockitoHamcrest.argThat (org.mockito.hamcrest.MockitoHamcrest.argThat)18 Iterator (java.util.Iterator)17 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)17 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)15 COLLECTION_NAME_PROPERTY_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME)13 DATABASE_LABEL (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL)13 ENTITY_TYPE_NAME_PROPERTY_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME)13 HAS_ARCHETYPE_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME)13 HAS_DISPLAY_NAME_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME)13 HAS_ENTITY_NODE_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME)13 HAS_ENTITY_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME)13