Search in sources :

Example 56 with TinkerPopGraphManager

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

the class WomenWritersJsonCrudServiceTest method getReturnsAJsonNodeWithARelationsPropertyWithAuthorsWithTheirGenderOfEachCreatedWork.

@Test
public void getReturnsAJsonNodeWithARelationsPropertyWithAuthorsWithTheirGenderOfEachCreatedWork() throws Exception {
    UUID pers1Id = UUID.randomUUID();
    TinkerPopGraphManager graphManager = newGraph().withVertex("work1", v -> v.withOutgoingRelation("isCreatedBy", "pers1", r -> r.withIsLatest(true).withAccepted("wwrelation", true)).withVre("ww").withVre("").withType("document").isLatest(true).withTimId(UUID.randomUUID().toString())).withVertex("work2", v -> v.withOutgoingRelation("isCreatedBy", "pers1", r -> r.withIsLatest(true).withAccepted("wwrelation", true)).withOutgoingRelation("isCreatedBy", "pers2", r -> r.withIsLatest(true).withAccepted("wwrelation", true)).withVre("ww").withVre("").withType("document").isLatest(true).withTimId(UUID.randomUUID().toString())).withVertex("pers1", v -> v.withVre("ww").withVre("").withType("person").withProperty("displayName", "author1").withProperty("wwperson_gender", "FEMALE").isLatest(true).withTimId(pers1Id.toString())).withVertex("pers2", v -> v.withVre("ww").withVre("").withType("person").withProperty("displayName", "author2").withProperty("wwperson_gender", "FEMALE").isLatest(true).withTimId(UUID.randomUUID().toString())).withVertex("relationType", v -> v.withType("relationType").withVre("").withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).wrap();
    WomenWritersJsonCrudService instance = createInstance(graphManager);
    JsonNode result = instance.get("wwpersons", pers1Id);
    assertThat(result.toString(), sameJSONAs(jsnO("@relations", jsnO("isCreatorOf", jsnA(jsnO("authors", jsnA(jsnO("displayName", jsn("author1"), "gender", jsn("FEMALE")))), jsnO("authors", jsnA(jsnO("displayName", jsn("author1"), "gender", jsn("FEMALE")), jsnO("displayName", jsn("author2"), "gender", jsn("FEMALE"))))))).toString()).allowingExtraUnexpectedFields().allowingAnyArrayOrdering());
}
Also used : UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TimbuctooActionsStubs(nl.knaw.huygens.timbuctoo.core.TimbuctooActionsStubs) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) Converters.personNames(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.personNames) Test(org.junit.Test) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Mockito(org.mockito.Mockito) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) JsonNode(com.fasterxml.jackson.databind.JsonNode) UUID(java.util.UUID) Test(org.junit.Test)

Example 57 with TinkerPopGraphManager

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

the class DatabaseValidatorTest method checkRunsAllTheDatabaseChecksForEachVertex.

@Test
public void checkRunsAllTheDatabaseChecksForEachVertex() {
    String id1 = "id1";
    String id2 = "id2";
    TinkerPopGraphManager graph = makeGraph(id1, id2);
    DatabaseCheck databaseCheck1 = mock(DatabaseCheck.class);
    DatabaseCheck databaseCheck2 = mock(DatabaseCheck.class);
    DatabaseValidator instance = new DatabaseValidator(graph, databaseCheck1, databaseCheck2);
    instance.check();
    verify(databaseCheck1).check(argThat(likeVertex().withTimId(id1)));
    verify(databaseCheck1).check(argThat(likeVertex().withTimId(id2)));
    verify(databaseCheck2).check(argThat(likeVertex().withTimId(id1)));
    verify(databaseCheck2).check(argThat(likeVertex().withTimId(id2)));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 58 with TinkerPopGraphManager

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

the class DatabaseValidatorTest method checkReturnsTheValidationResult.

@Test
public void checkReturnsTheValidationResult() {
    TinkerPopGraphManager graph = makeGraph("id1", "id2");
    DatabaseValidator instance = new DatabaseValidator(graph);
    ValidationResult result = instance.check();
    assertThat(result, is(notNullValue()));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 59 with TinkerPopGraphManager

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

the class DatabaseValidatorTest method checkReturnsAValidValidationResultWhenAllOfTheChecksSucceed.

@Test
public void checkReturnsAValidValidationResultWhenAllOfTheChecksSucceed() {
    TinkerPopGraphManager graph = makeGraph("id", "id2");
    DatabaseValidator instance = new DatabaseValidator(graph, validDatabaseCheck());
    ValidationResult result = instance.check();
    assertThat(result.isValid(), is(true));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 60 with TinkerPopGraphManager

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

the class DatabaseValidatorTest method checkCallsInitAndFinish.

@Test
public void checkCallsInitAndFinish() {
    TinkerPopGraphManager graph = makeGraph("1");
    DatabaseCheck databaseCheck1 = mock(DatabaseCheck.class);
    DatabaseCheck databaseCheck2 = mock(DatabaseCheck.class);
    DatabaseValidator instance = new DatabaseValidator(graph, databaseCheck1, databaseCheck2);
    instance.check();
    InOrder inOrder = inOrder(databaseCheck1, databaseCheck2);
    inOrder.verify(databaseCheck1).init(any(Graph.class), any(GraphDatabaseService.class));
    inOrder.verify(databaseCheck2).init(any(Graph.class), any(GraphDatabaseService.class));
    inOrder.verify(databaseCheck1).check(any(Vertex.class));
    inOrder.verify(databaseCheck2).check(any(Vertex.class));
    inOrder.verify(databaseCheck1).finish();
    inOrder.verify(databaseCheck2).finish();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) InOrder(org.mockito.InOrder) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) 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