Search in sources :

Example 11 with VresBuilder

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

the class JsonToEntityMapperTest method newUpdateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted.

@Test(expected = IOException.class)
public void newUpdateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted() throws Exception {
    Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons", c -> c.withProperty("name", localProperty("wwname")).withProperty("age", localProperty("wwage")))).build().getCollection("wwpersons").get();
    ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn(12), "^rev", jsn(2));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    instance.newUpdateEntity(collection, UUID.randomUUID(), input);
}
Also used : TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) IOException(java.io.IOException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UUID(java.util.UUID) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) 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 VresBuilder

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

the class JsonToEntityMapperTest method newUpdateEntityThrowsAnIoExceptionWhenItDoesNotContainARevProperty.

@Test
public void newUpdateEntityThrowsAnIoExceptionWhenItDoesNotContainARevProperty() throws Exception {
    Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons", c -> c.withProperty("name", localProperty("wwname")).withProperty("age", localProperty("wwage")))).build().getCollection("wwpersons").get();
    ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn("12"), "^rev", jsn(2));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    instance.newUpdateEntity(collection, UUID.randomUUID(), input);
}
Also used : TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) IOException(java.io.IOException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UUID(java.util.UUID) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 13 with VresBuilder

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

the class FulltextIndexChangeListenerTest method doesNotThrowWhenDisplayNameTraversalYieldsNoResults.

@Test
public void doesNotThrowWhenDisplayNameTraversalYieldsNoResults() {
    final String theMissingPropertyName = "missingProperty_name";
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("newVertex", v -> v.withProperty("locateMe", "here")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty(theMissingPropertyName)))).build().getCollection("vrecolls").get();
    Vertex newVertex = graphWrapper.getGraph().traversal().V().has("locateMe", "here").next();
    instance.onAddToCollection(collection, Optional.empty(), newVertex);
}
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 14 with VresBuilder

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

the class FulltextIndexChangeListenerTest method onPropertyUpdateRemovesTheOldVertexFromTheIndexBeforeAddingTheNewOne.

@Test
public void onPropertyUpdateRemovesTheOldVertexFromTheIndexBeforeAddingTheNewOne() {
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("newVertex", v -> v.withProperty("vrecoll_name", "new")).withVertex(v -> v.withProperty("vrecoll_name", "old").withOutgoingRelation("VERSION_OF", "newVertex")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty("vrecoll_name")))).build().getCollection("vrecolls").get();
    Vertex oldVertex = graphWrapper.getGraph().traversal().V().has("vrecoll_name", "old").next();
    Vertex newVertex = graphWrapper.getGraph().traversal().V().has("vrecoll_name", "new").next();
    instance.onPropertyUpdate(collection, Optional.of(oldVertex), newVertex);
    verify(indexHandler).upsertIntoQuickSearchIndex(collection, "new", newVertex, oldVertex);
}
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 15 with VresBuilder

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

the class FulltextIndexChangeListenerTest method onCreateAddsItemsToTheIndexOfTheProvidedCollection.

@Test
public void onCreateAddsItemsToTheIndexOfTheProvidedCollection() {
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withProperty("vrecoll_name", "foo")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty("vrecoll_name")))).build().getCollection("vrecolls").get();
    Vertex vertex = graphWrapper.getGraph().traversal().V().next();
    instance.onCreate(collection, vertex);
    verify(indexHandler).upsertIntoQuickSearchIndex(collection, "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)

Aggregations

VresBuilder (nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder)17 Test (org.junit.Test)16 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)15 PropertyTypes.localProperty (nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty)15 List (java.util.List)11 UUID (java.util.UUID)11 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 IOException (java.io.IOException)10 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)10 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)10 JsonToEntityMapper (nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper)10 JsonBuilder (nl.knaw.huygens.timbuctoo.util.JsonBuilder)10 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 Matchers.allOf (org.hamcrest.Matchers.allOf)10 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)10 Matchers.equalTo (org.hamcrest.Matchers.equalTo)10 Matchers.hasItem (org.hamcrest.Matchers.hasItem)10 Matchers.is (org.hamcrest.Matchers.is)10