Search in sources :

Example 16 with RelationIdTestResource

use of io.crnk.core.mock.models.RelationIdTestResource 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)

Aggregations

RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)16 QuerySpec (io.crnk.core.queryspec.QuerySpec)13 Document (io.crnk.core.engine.document.Document)12 Resource (io.crnk.core.engine.document.Resource)11 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)9 Response (io.crnk.core.engine.dispatcher.Response)3 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)3 Schedule (io.crnk.core.mock.models.Schedule)3 ScheduleRepositoryImpl (io.crnk.core.mock.repository.ScheduleRepositoryImpl)3 Before (org.junit.Before)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 Relationship (io.crnk.core.engine.document.Relationship)2 RelationshipsResourcePatch (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePatch)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 Project (io.crnk.core.mock.models.Project)2 Task (io.crnk.core.mock.models.Task)2 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)2 TaskRepository (io.crnk.core.mock.repository.TaskRepository)2