Search in sources :

Example 56 with ResourceIdentifier

use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.

the class MultiValuedRelationIdLookupTest method check.

private void check(boolean setRelatedEntity, boolean setRelatedId) {
    RelationIdTestResource entity = new RelationIdTestResource();
    entity.setId(2L);
    entity.setName("test");
    if (setRelatedId) {
        entity.setTestMultipleValueIds(Arrays.asList(3L, 4L));
    } else {
        entity.setTestMultipleValueIds(null);
    }
    if (setRelatedEntity) {
        entity.setTestMultipleValues(Arrays.asList(schedule3, schedule4));
    }
    QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
    querySpec.includeRelation(Arrays.asList("testMultipleValues"));
    Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Assert.assertEquals("relationIdTest", resource.getType());
    Assert.assertEquals("test", resource.getAttributes().get("name").asText());
    Nullable<ResourceIdentifier> data = resource.getRelationships().get("testMultipleValues").getSingleData();
    Assert.assertTrue(data.isPresent());
    if (setRelatedId) {
        Assert.assertNotNull(data.get());
        Assert.assertEquals(2, document.getIncluded().size());
        Assert.assertEquals("3", document.getIncluded().get(0).getId());
        Assert.assertEquals("4", document.getIncluded().get(1).getId());
        if (setRelatedEntity) {
            Assert.assertEquals(0, scheduleRepository.getNumFindAll());
        } else {
            Assert.assertEquals(1, scheduleRepository.getNumFindAll());
        }
    } else {
        Assert.assertNull(data.get());
    }
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Resource(io.crnk.core.engine.document.Resource) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource)

Example 57 with ResourceIdentifier

use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.

the class ResourceIdBasedRelationIdLookupTest method check.

private void check(boolean setRelatedEntity, boolean setRelatedId) {
    RelationIdTestResource entity = new RelationIdTestResource();
    entity.setId(2L);
    entity.setName("test");
    if (setRelatedId) {
        entity.setTestResourceIdRefId(new ResourceIdentifier("3", "schedules"));
    }
    if (setRelatedEntity) {
        entity.setTestResourceIdRef(schedule);
    }
    QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
    querySpec.includeRelation(Arrays.asList("testResourceIdRef"));
    Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Assert.assertEquals("relationIdTest", resource.getType());
    Assert.assertEquals("test", resource.getAttributes().get("name").asText());
    Nullable<ResourceIdentifier> data = resource.getRelationships().get("testResourceIdRef").getSingleData();
    Assert.assertTrue(data.isPresent());
    if (setRelatedId) {
        Assert.assertNotNull(data.get());
        Assert.assertEquals(1, document.getIncluded().size());
        Assert.assertEquals("3", document.getIncluded().get(0).getId());
        Assert.assertEquals(setRelatedEntity ? 0 : 1, scheduleRepository.getNumFindAll());
    } else {
        Assert.assertNull(data.get());
        Assert.assertEquals(0, scheduleRepository.getNumFindAll());
    }
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Resource(io.crnk.core.engine.document.Resource) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource)

Example 58 with ResourceIdentifier

use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.

the class SerializeOnlyIdRelationIdLookupTest method check.

private void check(boolean setRelatedEntity, boolean setRelatedId) {
    RelationIdTestResource entity = new RelationIdTestResource();
    entity.setId(2L);
    entity.setName("test");
    if (setRelatedId) {
        entity.setTestSerializeOnlyIdId(3L);
    }
    if (setRelatedEntity) {
        entity.setTestSerializeOnlyId(schedule);
    }
    QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
    Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Assert.assertEquals("relationIdTest", resource.getType());
    Assert.assertEquals("test", resource.getAttributes().get("name").asText());
    Nullable<ResourceIdentifier> data = resource.getRelationships().get("testSerializeOnlyId").getSingleData();
    Assert.assertTrue(data.isPresent());
    Assert.assertEquals(0, scheduleRepository.getNumFindAll());
    Assert.assertEquals(0, document.getIncluded().size());
    if (setRelatedEntity || setRelatedId) {
        Assert.assertNotNull(data.get());
    } else {
        Assert.assertNull(data.get());
    }
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Resource(io.crnk.core.engine.document.Resource) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource)

Example 59 with ResourceIdentifier

use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.

the class RawResourceFieldAccessorTest method relationship.

@Test
public void relationship() {
    RawResourceFieldAccessor accessor = new RawResourceFieldAccessor("address", ResourceFieldType.RELATIONSHIP, ResourceIdentifier.class);
    ResourceIdentifier value = (ResourceIdentifier) accessor.getValue(resource);
    Assert.assertEquals("zurich", value.getId());
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) RawResourceFieldAccessor(io.crnk.core.engine.internal.information.resource.RawResourceFieldAccessor) Test(org.junit.Test)

Example 60 with ResourceIdentifier

use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.

the class DependencyOrderStrategyTest method addOneDependency.

private void addOneDependency(Operation op1, Operation op2, String relationshipName) {
    Resource resource1 = op1.getValue();
    Resource resource2 = op2.getValue();
    Relationship relationship = resource1.getRelationships().get(relationshipName);
    if (relationship == null) {
        relationship = new Relationship();
        resource1.getRelationships().put(relationshipName, relationship);
    }
    ResourceIdentifier resourceId = new ResourceIdentifier(resource2.getId(), resource2.getType());
    relationship.setData(Nullable.of((Object) resourceId));
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource)

Aggregations

ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)60 Resource (io.crnk.core.engine.document.Resource)42 Document (io.crnk.core.engine.document.Document)40 Test (org.junit.Test)33 Relationship (io.crnk.core.engine.document.Relationship)31 QuerySpec (io.crnk.core.queryspec.QuerySpec)25 Response (io.crnk.core.engine.dispatcher.Response)14 Task (io.crnk.core.mock.models.Task)13 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)11 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)11 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)11 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)9 Serializable (java.io.Serializable)9 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)8 Project (io.crnk.core.mock.models.Project)8 ArrayList (java.util.ArrayList)8 ResourceField (io.crnk.core.engine.information.resource.ResourceField)6 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)6 LazyTask (io.crnk.core.mock.models.LazyTask)6 AbstractDocumentMapperTest (io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest)4