Search in sources :

Example 11 with GraphWrapper

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

the class FulltextIndexChangeListenerTest method onCreateHandlesWwDocumentsUsingCustomLogic.

@Test
public void onCreateHandlesWwDocumentsUsingCustomLogic() {
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("doc", v -> v.withProperty("wwdocument_name", "foo").withOutgoingRelation("isCreatedBy", "authorA", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withOutgoingRelation("isCreatedBy", "authorB", r -> r.withAccepted("wwrelation", true).withIsLatest(true))).withVertex("authorA", v -> v.withProperty("wwperson_name", "authorA")).withVertex("authorB", v -> v.withProperty("wwperson_name", "authorB")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("womenwriters", "ww", vre -> vre.withCollection("wwdocuments", coll -> coll.withDisplayName(localProperty("wwdocument_name"))).withCollection("wwpersons", coll -> coll.withDisplayName(localProperty("wwperson_name")))).build().getCollection("wwdocuments").get();
    Vertex vertex = graphWrapper.getGraph().traversal().V().next();
    instance.onCreate(collection, vertex);
    verify(indexHandler).upsertIntoQuickSearchIndex(collection, "authorA; authorB foo", vertex, null);
}
Also used : GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Optional(java.util.Optional) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 12 with GraphWrapper

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

the class DatabaseFixerTest method fixSetsTheAcceptedPropertiesToTrue.

@Test
public void fixSetsTheAcceptedPropertiesToTrue() {
    UUID rel1Id = UUID.fromString("ff65089c-2ded-4af0-95e7-0476979f96b8");
    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)).withAccepted("vrerel", false))).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).withProperty("vrerel_accepted", true), likeEdge().withId(rel1Id.toString()).withProperty("rev", 2).withProperty("vrerel_accepted", false)));
}
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 13 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper 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 14 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper 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 15 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper 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)

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