Search in sources :

Example 1 with LogEntryFactory

use of nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory in project timbuctoo by HuygensING.

the class DatabaseLogIntegrationTest method generateFirstAddsTheVerticesAndThenAddsTheEdgesForATimeStamp.

@Test
public void generateFirstAddsTheVerticesAndThenAddsTheEdgesForATimeStamp() {
    LogOutput logOutput = mock(LogOutput.class);
    UUID rel1Uuid = UUID.fromString("ff65089c-2ded-4af0-95e7-0476979f96b8");
    UUID rel2Uuid = UUID.fromString("a628b090-ec7f-4608-9356-61728355ad5a");
    GraphWrapper graphWrapper = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty("modified", changeStringWithTimestamp(1000L)).withProperty("rev", 1)).withVertex("v2", v -> v.withTimId("id2").withProperty("modified", changeStringWithTimestamp(1001L)).withProperty("rev", 1).withOutgoingRelation("isRelatedTo", "v2", r -> r.withTim_id(rel1Uuid).withModified(changeWithTimestamp(1002L)).withRev(1))).withVertex("v3", v -> v.withTimId("id3").withProperty("modified", changeStringWithTimestamp(1002L)).withProperty("rev", 1)).withVertex("v4", v -> v.withTimId("id3").withProperty("modified", changeStringWithTimestamp(4000L)).withProperty("rev", 2).withIncomingRelation("isRelatedTo", "v1", r -> r.withTim_id(rel2Uuid).withModified(changeWithTimestamp(3000L)).withRev(1)).withIncomingRelation("VERSION_OF", "v3")).wrap();
    DatabaseLog logGenerator = new DatabaseLog(graphWrapper, new LogEntryFactory(), logOutput);
    logGenerator.generate();
    InOrder inOrder = inOrder(logOutput);
    inOrder.verify(logOutput).newVertex(argThat(likeVertex().withTimId("id1")));
    inOrder.verify(logOutput).newVertex(argThat(likeVertex().withTimId("id2")));
    inOrder.verify(logOutput).newVertex(argThat(likeVertex().withTimId("id3")));
    inOrder.verify(logOutput).newEdge(argThat(likeEdge().withId(rel1Uuid.toString())));
    inOrder.verify(logOutput).newEdge(argThat(likeEdge().withId(rel2Uuid.toString())));
    inOrder.verify(logOutput).updateVertex(argThat(likeVertex().withTimId("id3")));
}
Also used : LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) InOrder(org.mockito.InOrder) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) Test(org.junit.Test) UUID(java.util.UUID) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) 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) Mockito.mock(org.mockito.Mockito.mock) LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) InOrder(org.mockito.InOrder) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with LogEntryFactory

use of nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory in project timbuctoo by HuygensING.

the class DatabaseLogTest method setUp.

@Before
public void setUp() throws Exception {
    objectMapper = new ObjectMapper();
    logEntryFactory = mock(LogEntryFactory.class);
    vertexLogEntry = mock(LogEntry.class);
    given(logEntryFactory.createForVertex(any(Vertex.class))).willReturn(vertexLogEntry);
    given(logEntryFactory.createForEdge(any(Edge.class))).willReturn(mock(LogEntry.class));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with LogEntryFactory

use of nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory in project timbuctoo by HuygensING.

the class DatabaseLogTest method generateIteratesThroughAllVerticesOrderedByModifiedDate.

@Test
public void generateIteratesThroughAllVerticesOrderedByModifiedDate() throws Exception {
    String first = "first";
    String second = "second";
    String third = "third";
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withTimId(first).withProperty("modified", getChangeStringWithTimestamp(1464346423L)).withProperty("rev", 1)).withVertex(v -> v.withTimId(third).withProperty("modified", getChangeStringWithTimestamp(1464346425L)).withProperty("rev", 1)).withVertex(v -> v.withTimId(second).withProperty("modified", getChangeStringWithTimestamp(1464346424L)).withProperty("rev", 1)).wrap();
    DatabaseLog instance = createInstance(graphWrapper);
    instance.generate();
    InOrder inOrder = inOrder(logEntryFactory);
    inOrder.verify(logEntryFactory).createForVertex(argThat(likeVertex().withTimId(first)));
    inOrder.verify(logEntryFactory).createForVertex(argThat(likeVertex().withTimId(second)));
    inOrder.verify(logEntryFactory).createForVertex(argThat(likeVertex().withTimId(third)));
}
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) InOrder(org.mockito.InOrder) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Test(org.junit.Test)

Example 4 with LogEntryFactory

use of nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory in project timbuctoo by HuygensING.

the class DatabaseLogTest method generateAppendsEachVersionOfAVertexOnlyOnce.

@Test
public void generateAppendsEachVersionOfAVertexOnlyOnce() {
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withTimId("id1").withProperty("modified", getChangeStringWithTimestamp(1464346423L)).withProperty("rev", 1)).withVertex(v -> v.withTimId("id1").withProperty("modified", getChangeStringWithTimestamp(1464346425L)).withProperty("rev", 2)).withVertex(v -> v.withTimId("id1").withProperty("modified", getChangeStringWithTimestamp(1464346424L)).withProperty("rev", 2)).wrap();
    DatabaseLog instance = createInstance(graphWrapper);
    instance.generate();
    verify(logEntryFactory).createForVertex(argThat(likeVertex().withTimId("id1").withProperty("rev", 1)));
    verify(logEntryFactory, times(1)).createForVertex(argThat(likeVertex().withTimId("id1").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) Test(org.junit.Test)

Example 5 with LogEntryFactory

use of nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory 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)

Aggregations

LogEntryFactory (nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory)5 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)5 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)5 ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)5 UUID (java.util.UUID)4 Change (nl.knaw.huygens.timbuctoo.model.Change)4 GraphWrapper (nl.knaw.huygens.timbuctoo.server.GraphWrapper)4 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)4 Edge (org.apache.tinkerpop.gremlin.structure.Edge)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 JsonProcessingException (org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException)4 Before (org.junit.Before)4 Test (org.junit.Test)4 InOrder (org.mockito.InOrder)4 Mockito.inOrder (org.mockito.Mockito.inOrder)4 Mockito.mock (org.mockito.Mockito.mock)4 MockitoHamcrest.argThat (org.mockito.hamcrest.MockitoHamcrest.argThat)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 BDDMockito.given (org.mockito.BDDMockito.given)3 Mockito.verify (org.mockito.Mockito.verify)3