Search in sources :

Example 51 with TinkerPopGraphManager

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

the class DatabaseTest method findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection.

@Test
public void findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection() {
    CollectionDescription desc = CollectionDescription.createCollectionDescription("collection", VRE_NAME);
    TinkerPopGraphManager graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, desc.getEntityTypeName()).withProperty(COLLECTION_NAME_PROPERTY_NAME, desc.getCollectionName()).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityVertex")).withVertex("entityVertex", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity1").withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity2")).withVertex("entity1", v -> {
    }).withVertex("entity2", v -> {
    }).withVertex("entityOfOtherCollection", v -> {
    }).wrap();
    Database instance = new Database(graphWrapper);
    Collection collection = mock(Collection.class);
    when(collection.getDescription()).thenReturn(desc);
    Set<Entity> entitiesByCollection = instance.findEntitiesByCollection(collection);
    assertThat(entitiesByCollection, hasSize(2));
}
Also used : HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) Matchers.not(org.hamcrest.Matchers.not) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Set(java.util.Set) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Mockito.when(org.mockito.Mockito.when) T(org.apache.tinkerpop.gremlin.structure.T) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) List(java.util.List) Ignore(org.junit.Ignore) Node(org.apache.jena.graph.Node) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 52 with TinkerPopGraphManager

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

the class PropertyHelperTest method movePropertiesMovesThePropertiesToTheNewCollection.

@Test
public void movePropertiesMovesThePropertiesToTheNewCollection() {
    String vreName = "vreName";
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vertex oldColVertex = graphManager.getGraph().addVertex(ENTITY_TYPE_NAME_PROPERTY_NAME, "oldCollection");
    Collection oldCollection = new Collection(vreName, oldColVertex, graphManager);
    Vertex newColVertex = graphManager.getGraph().addVertex(ENTITY_TYPE_NAME_PROPERTY_NAME, "newCollection");
    Collection newCollection = new Collection(vreName, newColVertex, graphManager);
    Vertex vertex = graphManager.getGraph().addVertex("vreNameoldCollection_prop", "value1", "vreNameoldCollection2_prop", "value1");
    Entity entity = new Entity(vertex, Sets.newHashSet(oldCollection, newCollection));
    new PropertyHelper().movePropertiesToNewCollection(entity, oldCollection, newCollection);
    assertThat(vertex.value("vreNameoldCollection2_prop"), is("value1"));
    assertThat(vertex.value("vreNamenewCollection_prop"), is("value1"));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 53 with TinkerPopGraphManager

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

the class RdfImporterTest method importRdfReloadsTheDatabaseConfigurationAfterImport.

@Test
public void importRdfReloadsTheDatabaseConfigurationAfterImport() {
    TinkerPopGraphManager graphWrapper = newGraph().wrap();
    TripleImporter tripleImporter = mock(TripleImporter.class);
    final Vres vres = mock(DatabaseConfiguredVres.class);
    RdfImporter instance = new RdfImporter(graphWrapper, VRE_NAME, vres, tripleImporter);
    instance.importRdf(getTripleStream(EXAMPLE_TRIPLE_STRING), "application/n-quads");
    InOrder inOrder = inOrder(tripleImporter, vres);
    inOrder.verify(tripleImporter).importTriple(eq(true), any(Triple.class));
    inOrder.verify(vres).reload();
}
Also used : Triple(org.apache.jena.graph.Triple) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) DatabaseConfiguredVres(nl.knaw.huygens.timbuctoo.model.vre.vres.DatabaseConfiguredVres) InOrder(org.mockito.InOrder) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 54 with TinkerPopGraphManager

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

the class WomenWritersJsonCrudServiceTest method getReturnsAJsonNodeWithARelationsPropertyWithTheGenderOfTheAuthors.

@Test
public void getReturnsAJsonNodeWithARelationsPropertyWithTheGenderOfTheAuthors() throws InvalidCollectionException, NotFoundException {
    UUID workId = UUID.randomUUID();
    TinkerPopGraphManager graphManager = newGraph().withVertex("work1", v -> {
        v.withOutgoingRelation("isCreatedBy", "pers1").withOutgoingRelation("isCreatedBy", "pers2").withVre("ww").withVre("").withType("document").isLatest(true).withTimId(workId.toString());
    }).withVertex("pers1", v -> v.withVre("ww").withVre("").withType("person").withProperty("displayName", "author1").withProperty("wwperson_gender", "FEMALE").isLatest(true).withTimId(UUID.randomUUID().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("wwdocuments", workId);
    assertThat(result.toString(), sameJSONAs(jsnO("@relations", jsnO("isCreatedBy", jsnA(jsnO("displayName", jsn("author1"), "gender", jsn("FEMALE")), jsnO("displayName", jsn("author2"), "gender", jsn("FEMALE"))))).toString()).allowingAnyArrayOrdering().allowingExtraUnexpectedFields());
}
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 55 with TinkerPopGraphManager

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

the class WomenWritersJsonCrudServiceTest method getReturnsTheLanguagesOfTheDocumentsWrittenByAPerson.

@Test
public void getReturnsTheLanguagesOfTheDocumentsWrittenByAPerson() throws InvalidCollectionException, NotFoundException {
    UUID pers1Id = UUID.randomUUID();
    TinkerPopGraphManager graphManager = newGraph().withVertex("work1", v -> v.withOutgoingRelation("isCreatedBy", "pers1", r -> r.withIsLatest(true).withAccepted("wwrelation", true)).withOutgoingRelation("hasWorkLanguage", "lang1", 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("hasWorkLanguage", "lang2", 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("lang1", v -> v.withVre("ww").withVre("").withType("language").withProperty("wwlanguage_name", "French").isLatest(true).withTimId(UUID.randomUUID().toString())).withVertex("lang2", v -> v.withVre("ww").withVre("").withType("language").withProperty("wwlanguage_name", "Dutch").isLatest(true).withTimId(UUID.randomUUID().toString())).withVertex("relationType1", v -> v.withType("relationType").withVre("").withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).withVertex("relationType2", v -> v.withType("relationType").withVre("").withProperty("relationtype_regularName", "hasWorkLanguage").withProperty("relationtype_inverseName", "isWorkLanguageOf")).wrap();
    WomenWritersJsonCrudService instance = createInstance(graphManager);
    JsonNode result = instance.get("wwpersons", pers1Id);
    assertThat(result.toString(), sameJSONAs(jsnO("@authorLanguages", jsnA(jsn("French"), jsn("Dutch"))).toString()).allowingAnyArrayOrdering().allowingExtraUnexpectedFields());
}
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)

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