Search in sources :

Example 16 with TimProperty

use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.

the class EntityToJsonMapperTest method mapEntityMapsTheProperties.

@Test
public void mapEntityMapsTheProperties() throws Exception {
    ReadEntityImpl readEntity = new ReadEntityImpl();
    readEntity.setId(UUID.randomUUID());
    String userId = "userId";
    Change change = new Change(Instant.now().toEpochMilli(), userId, null);
    readEntity.setCreated(change);
    readEntity.setModified(change);
    String type = "otherType";
    readEntity.setTypes(Lists.newArrayList("type", type));
    readEntity.setDeleted(false);
    readEntity.setRev(1);
    readEntity.setPid("pid");
    ArrayList<TimProperty<?>> properties = Lists.newArrayList();
    properties.add(new StringProperty("name", "Name"));
    readEntity.setProperties(properties);
    EntityToJsonMapper instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn(type);
    ObjectNode resutlJson = instance.mapEntity(collection, readEntity, false, (readEntity1, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    assertThat(resutlJson.toString(), sameJSONAs(jsnO("name", jsn("Name")).toString()).allowingExtraUnexpectedFields());
}
Also used : ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) Test(org.junit.Test)

Example 17 with TimProperty

use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.

the class EntityToJsonMapperTest method doesNotAddNonConvertableProperties.

@Test
public void doesNotAddNonConvertableProperties() {
    ReadEntityImpl readEntity = new ReadEntityImpl();
    readEntity.setId(UUID.randomUUID());
    String userId = "userId";
    Change change = new Change(Instant.now().toEpochMilli(), userId, null);
    readEntity.setCreated(change);
    readEntity.setModified(change);
    String type = "otherType";
    readEntity.setTypes(Lists.newArrayList("type", type));
    readEntity.setDeleted(false);
    readEntity.setRev(1);
    readEntity.setPid("pid");
    ArrayList<TimProperty<?>> properties = Lists.newArrayList();
    properties.add(new HyperLinksProperty("nonParsableProp", "Name"));
    readEntity.setProperties(properties);
    EntityToJsonMapper instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn(type);
    ObjectNode resutlJson = instance.mapEntity(collection, readEntity, false, (readEntity1, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    assertThat(Lists.newArrayList(resutlJson.fieldNames()), not(hasItem("nonParsableProp")));
}
Also used : ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HyperLinksProperty(nl.knaw.huygens.timbuctoo.core.dto.property.HyperLinksProperty) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) Test(org.junit.Test)

Example 18 with TimProperty

use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty 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 19 with TimProperty

use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty 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)

Example 20 with TimProperty

use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.

the class TinkerPopPropertyConverterTest method fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType.

@Test
public void fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType() throws UnknownPropertyException, IOException {
    Collection collection = mock(Collection.class);
    ReadableProperty readableProperty = mock(ReadableProperty.class);
    when(readableProperty.getUniqueTypeId()).thenReturn("string");
    when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
    TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
    TimProperty property = instance.from(PROPERTY_NAME, STRING_VALUE);
    assertThat(property, is(instanceOf(StringProperty.class)));
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Aggregations

TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)21 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)20 Test (org.junit.Test)17 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)13 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)12 CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)12 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)12 IOException (java.io.IOException)10 UUID (java.util.UUID)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 List (java.util.List)9 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)8 Change (nl.knaw.huygens.timbuctoo.model.Change)8 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)8 PropertyTypes.localProperty (nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty)7 VresBuilder (nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Matchers.allOf (org.hamcrest.Matchers.allOf)7 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 Matchers.equalTo (org.hamcrest.Matchers.equalTo)7