Search in sources :

Example 6 with VresBuilder

use of nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder 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 7 with VresBuilder

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

the class TinkerPopOperationsForMigrationsTest method itGIvesYouAnInitDb.

@Test
public void itGIvesYouAnInitDb() throws JsonProcessingException {
    final TinkerPopGraphManager graphManager = newGraph().wrap();
    TinkerPopOperations ops = forInitDb(graphManager);
    assertThat(ops.databaseIsEmptyExceptForMigrations(), is(true));
    ops.initDb(new VresBuilder().withVre("Admin", "", vre -> vre.withCollection("relations", CollectionBuilder::isRelationCollection)).build(), relationType("concept", "hasFirstPerson", "person", "someRel", false, false, false, UUID.randomUUID()));
    assertThat(graphManager.getGraph().traversal().V().count().next(), is(4L));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) TinkerPopOperations(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperations) Test(org.junit.Test)

Example 8 with VresBuilder

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

the class JsonToEntityMapperTest method newUpdateEntityIgnoresThePrefixedFields.

@Test
public void newUpdateEntityIgnoresThePrefixedFields() throws Exception {
    Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons")).build().getCollection("wwpersons").get();
    ObjectNode input = JsonBuilder.jsnO("_id", jsn("id"), "^rev", jsn(1), "@type", jsn("wwperson"));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    UpdateEntity updateEntity = instance.newUpdateEntity(collection, UUID.randomUUID(), input);
    assertThat(updateEntity.getProperties(), not(containsInAnyOrder(hasProperty("name", equalTo("_id")), hasProperty("name", equalTo("^rev")), hasProperty("name", equalTo("@type")))));
}
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) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) 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 9 with VresBuilder

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

the class JsonToEntityMapperTest method newCreateEntityIgnoresThePrefixedFields.

@Test
public void newCreateEntityIgnoresThePrefixedFields() throws Exception {
    Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons")).build().getCollection("wwpersons").get();
    ObjectNode input = JsonBuilder.jsnO("_id", jsn("id"), "^rev", jsn(1), "@type", jsn("wwperson"));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
    assertThat(properties, not(containsInAnyOrder(hasProperty("name", equalTo("_id")), hasProperty("name", equalTo("^rev")), hasProperty("name", equalTo("@type")))));
}
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) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 10 with VresBuilder

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

the class JsonToEntityMapperTest method newCreateEntityMapsTheJsonObjectToACreateEntity.

@Test
public void newCreateEntityMapsTheJsonObjectToACreateEntity() 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"));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
    assertThat(properties, containsInAnyOrder(allOf(hasProperty("name", equalTo("name")), hasProperty("value", equalTo("Hans"))), allOf(hasProperty("name", equalTo("age")), hasProperty("value", equalTo("12")))));
}
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) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) 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