Search in sources :

Example 21 with Vre

use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method saveReplacesAnExistingVertexForTheCollection.

@Test
public void saveReplacesAnExistingVertexForTheCollection() {
    final Vertex existingVertex = graph.addVertex(DATABASE_LABEL);
    existingVertex.property(Collection.COLLECTION_NAME_PROPERTY_NAME, "persons");
    final Vre vre = new Vre(vreName);
    timbuctooCollection("persons", "").build(vre);
    final Vertex result = save(vre.getCollectionForCollectionName("persons").get(), graph);
    assertThat(result, equalTo(existingVertex));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Example 22 with Vre

use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method saveCreatesARelationToTheArchetypeVariantCollectionVertex.

@Test
public void saveCreatesARelationToTheArchetypeVariantCollectionVertex() {
    final Vre vre = new Vre(vreName);
    final Graph graph = newGraph().withVertex(v -> {
        v.withLabel(DATABASE_LABEL);
        v.withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "persons");
        v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "person");
    }).build();
    timbuctooCollection("prefixedpersons", "prefixed").build(vre);
    final Vertex result = save(vre.getCollectionForCollectionName("prefixedpersons").get(), graph);
    assertThat(result.vertices(Direction.OUT, Collection.HAS_ARCHETYPE_RELATION_NAME).hasNext(), equalTo(true));
}
Also used : HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Lists(com.google.common.collect.Lists) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) StringToStringConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.StringToStringConverter) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) CollectionBuilder.timbuctooCollection(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder.timbuctooCollection) 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) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Maps(com.google.common.collect.Maps) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Example 23 with Vre

use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method saveDropsRelatedExistingPropertyVertices.

@Test
public void saveDropsRelatedExistingPropertyVertices() {
    final Vre vre = new Vre(vreName);
    final Vertex existingVertex = graph.addVertex(DATABASE_LABEL);
    final Vertex existingPropertyVertex = graph.addVertex(ReadableProperty.DATABASE_LABEL);
    final Vertex existingPropertyVertex2 = graph.addVertex(ReadableProperty.DATABASE_LABEL);
    final Vertex existingPropertyVertex3 = graph.addVertex(ReadableProperty.DATABASE_LABEL);
    existingVertex.property(Collection.COLLECTION_NAME_PROPERTY_NAME, "persons");
    existingVertex.addEdge(HAS_PROPERTY_RELATION_NAME, existingPropertyVertex);
    existingVertex.addEdge(HAS_DISPLAY_NAME_RELATION_NAME, existingPropertyVertex2);
    existingVertex.addEdge(HAS_INITIAL_PROPERTY_RELATION_NAME, existingPropertyVertex3);
    timbuctooCollection("persons", "").build(vre);
    save(vre.getCollectionForCollectionName("persons").get(), graph);
    assertThat(graph.traversal().V().hasLabel(ReadableProperty.DATABASE_LABEL).hasNext(), equalTo(false));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Example 24 with Vre

use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method saveSavesThePropertyConfigurations.

@Test
public void saveSavesThePropertyConfigurations() {
    final Vre vre = new Vre(vreName);
    timbuctooCollection("persons", "").withProperty("prop1", localProperty("person_prop1")).withProperty("prop2", localProperty("person_prop2")).withProperty("prop3", localProperty("person_prop3")).withDisplayName(localProperty("person_prop1")).build(vre);
    final Vertex result = save(vre.getCollectionForCollectionName("persons").get(), graph);
    final List<Vertex> propertyVertices = Lists.newArrayList(result.vertices(Direction.OUT, Collection.HAS_PROPERTY_RELATION_NAME));
    assertThat(propertyVertices, containsInAnyOrder(likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop1").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop1"), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop2").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop2"), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop3").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop3")));
    assertThat(result.vertices(Direction.OUT, HAS_DISPLAY_NAME_RELATION_NAME).next(), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, ReadableProperty.DISPLAY_NAME_PROPERTY_NAME).withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop1"));
    assertThat(result.vertices(Direction.OUT, HAS_INITIAL_PROPERTY_RELATION_NAME).next(), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop1").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop1"));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Example 25 with Vre

use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method saveAddsOrderingRelationsBetweenItsPropertyVerticesToMaintainSortorder.

@Test
public void saveAddsOrderingRelationsBetweenItsPropertyVerticesToMaintainSortorder() {
    final Vre vre = new Vre(vreName);
    timbuctooCollection("persons", "").withProperty("prop1", localProperty("person_prop1")).withProperty("prop2", localProperty("person_prop2")).withProperty("prop3", localProperty("person_prop3")).withDisplayName(localProperty("person_prop1")).build(vre);
    Vertex current = save(vre.getCollectionForCollectionName("persons").get(), graph).vertices(Direction.OUT, HAS_INITIAL_PROPERTY_RELATION_NAME).next();
    List<Vertex> result = Lists.newArrayList();
    result.add(current);
    while (current.vertices(Direction.OUT, ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME).hasNext()) {
        current = current.vertices(Direction.OUT, ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME).next();
        result.add(current);
    }
    assertThat(result.size(), equalTo(3));
    assertThat(result, contains(likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop1").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop1"), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop2").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop2"), likeVertex().withLabel(ReadableProperty.DATABASE_LABEL).withProperty(ReadableProperty.CLIENT_PROPERTY_NAME, "prop3").withProperty(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop3")));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Aggregations

Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)81 Test (org.junit.Test)71 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)48 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)46 VreStubs.minimalCorrectVre (nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre)44 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)43 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)41 Matchers.containsString (org.hamcrest.Matchers.containsString)35 List (java.util.List)34 Lists (com.google.common.collect.Lists)32 Optional (java.util.Optional)31 RdfProperty (nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty)31 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)30 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)30 Direction (org.apache.tinkerpop.gremlin.structure.Direction)30 Graph (org.apache.tinkerpop.gremlin.structure.Graph)30 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)30 Matchers.contains (org.hamcrest.Matchers.contains)30 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)30 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29