Search in sources :

Example 1 with JsonToEntityMapper

use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method getDataPropertiesIgnoresPropertiesWithValueEmptyString.

@Test
public void getDataPropertiesIgnoresPropertiesWithValueEmptyString() 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(""));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
    assertThat(properties, not(hasItem(hasProperty("name", equalTo("age")))));
}
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 2 with JsonToEntityMapper

use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method newUpdateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown.

@Test(expected = IOException.class)
public void newUpdateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown() 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("unknownProperty", jsn("value"), "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 3 with JsonToEntityMapper

use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method newCreateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted.

@Test(expected = IOException.class)
public void newCreateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted() 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();
    instance.getDataProperties(collection, 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 4 with JsonToEntityMapper

use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method newUpdateEntityMapsTheJsonObjectToAnUpdateEntity.

@Test
public void newUpdateEntityMapsTheJsonObjectToAnUpdateEntity() 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();
    int rev = 2;
    ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn("12"), "^rev", jsn(rev));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    UUID id = UUID.randomUUID();
    UpdateEntity updateEntity = instance.newUpdateEntity(collection, id, input);
    assertThat(updateEntity.getProperties(), containsInAnyOrder(allOf(hasProperty("name", equalTo("name")), hasProperty("value", equalTo("Hans"))), allOf(hasProperty("name", equalTo("age")), hasProperty("value", equalTo("12")))));
    assertThat(updateEntity.getId(), is(id));
    assertThat(updateEntity.getRev(), is(rev));
}
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) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with JsonToEntityMapper

use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method newCreateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown.

@Test(expected = IOException.class)
public void newCreateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown() 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("unknownProperty", jsn("value"), "age", jsn("12"));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    instance.getDataProperties(collection, 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)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 IOException (java.io.IOException)10 List (java.util.List)10 UUID (java.util.UUID)10 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)10 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)10 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)10 JsonToEntityMapper (nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper)10 PropertyTypes.localProperty (nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty)10 VresBuilder (nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder)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.hasProperty (org.hamcrest.Matchers.hasProperty)10 Matchers.is (org.hamcrest.Matchers.is)10 Matchers.not (org.hamcrest.Matchers.not)10