Search in sources :

Example 1 with LazyTask

use of io.crnk.core.mock.models.LazyTask in project crnk-framework by crnk-project.

the class DocumentMapperTest method testRelationshipSingleValuedLazy.

@Test
public void testRelationshipSingleValuedLazy() {
    LazyTask task = createLazyTask(2);
    Project project = createProject(3, "sample project");
    task.setLazyProject(project);
    Document document = mapper.toDocument(toResponse(task), createAdapter(Task.class));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Assert.assertEquals("lazy_tasks", resource.getType());
    Relationship relationship = resource.getRelationships().get("lazyProject");
    Assert.assertNotNull(relationship);
    Assert.assertEquals("https://service.local/lazy_tasks/2/relationships/lazyProject", getLinkText(relationship.getLinks().get("self")));
    Assert.assertEquals("https://service.local/lazy_tasks/2/lazyProject", getLinkText(relationship.getLinks().get("related")));
    Nullable<ResourceIdentifier> relationshipData = relationship.getSingleData();
    Assert.assertFalse(relationshipData.isPresent());
    Assert.assertTrue(document.getIncluded().isEmpty());
}
Also used : Project(io.crnk.core.mock.models.Project) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) LazyTask(io.crnk.core.mock.models.LazyTask) Task(io.crnk.core.mock.models.Task) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) LazyTask(io.crnk.core.mock.models.LazyTask) Document(io.crnk.core.engine.document.Document) Test(org.junit.Test)

Example 2 with LazyTask

use of io.crnk.core.mock.models.LazyTask in project crnk-framework by crnk-project.

the class DocumentMapperTest method testRelationshipIncludeRelation.

@Test
public void testRelationshipIncludeRelation() {
    LazyTask task = createLazyTask(2);
    Project project = createProject(3, "sample project");
    task.setProject(project);
    QuerySpec querySpec = new QuerySpec(LazyTask.class);
    querySpec.includeRelation(Arrays.asList("project"));
    Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Relationship relationship = resource.getRelationships().get("project");
    Assert.assertNotNull(relationship);
    ResourceIdentifier relationshipData = relationship.getSingleData().get();
    Assert.assertNotNull(relationshipData);
    Assert.assertEquals("3", relationshipData.getId());
    Assert.assertEquals("projects", relationshipData.getType());
    List<Resource> included = document.getIncluded();
    Assert.assertEquals(1, included.size());
    Assert.assertEquals("3", included.get(0).getId());
    Assert.assertEquals("projects", included.get(0).getType());
    Assert.assertEquals("sample project", included.get(0).getAttributes().get("name").asText());
}
Also used : Project(io.crnk.core.mock.models.Project) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) LazyTask(io.crnk.core.mock.models.LazyTask) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) Test(org.junit.Test)

Example 3 with LazyTask

use of io.crnk.core.mock.models.LazyTask in project crnk-framework by crnk-project.

the class DocumentMapperTest method testRelationshipIncludeMultiValued.

@Test
public void testRelationshipIncludeMultiValued() {
    LazyTask task = createLazyTask(2);
    Project project1 = createProject(3, "sample project3");
    Project project2 = createProject(4, "sample project4");
    task.setProjects(Arrays.asList(project1, project2));
    QuerySpec querySpec = new QuerySpec(LazyTask.class);
    querySpec.includeRelation(Arrays.asList("projects"));
    Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Relationship relationship = resource.getRelationships().get("projects");
    Assert.assertNotNull(relationship);
    List<ResourceIdentifier> relationshipData = relationship.getCollectionData().get();
    Assert.assertNotNull(relationshipData);
    Assert.assertEquals(2, relationshipData.size());
    Assert.assertEquals("3", relationshipData.get(0).getId());
    Assert.assertEquals("projects", relationshipData.get(0).getType());
    Assert.assertEquals("4", relationshipData.get(1).getId());
    Assert.assertEquals("projects", relationshipData.get(1).getType());
    Assert.assertFalse(document.getIncluded().isEmpty());
    List<Resource> included = document.getIncluded();
    Assert.assertEquals(2, included.size());
    Assert.assertEquals("3", included.get(0).getId());
    Assert.assertEquals("projects", included.get(0).getType());
    Assert.assertEquals("sample project3", included.get(0).getAttributes().get("name").asText());
    Assert.assertEquals("4", included.get(1).getId());
    Assert.assertEquals("projects", included.get(1).getType());
    Assert.assertEquals("sample project4", included.get(1).getAttributes().get("name").asText());
}
Also used : Project(io.crnk.core.mock.models.Project) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) LazyTask(io.crnk.core.mock.models.LazyTask) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) Test(org.junit.Test)

Example 4 with LazyTask

use of io.crnk.core.mock.models.LazyTask in project crnk-framework by crnk-project.

the class DocumentMapperTest method createLazyTask.

private LazyTask createLazyTask(long id) {
    LazyTask task = new LazyTask();
    task.setId(id);
    return task;
}
Also used : LazyTask(io.crnk.core.mock.models.LazyTask)

Example 5 with LazyTask

use of io.crnk.core.mock.models.LazyTask in project crnk-framework by crnk-project.

the class DocumentMapperTest method testRelationshipSingleValuedEager.

@Test
public void testRelationshipSingleValuedEager() {
    LazyTask task = createLazyTask(2);
    Project project = createProject(3, "sample project");
    task.setProject(project);
    Document document = mapper.toDocument(toResponse(task), createAdapter(Task.class));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Relationship relationship = resource.getRelationships().get("project");
    Assert.assertNotNull(relationship);
    ResourceIdentifier relationshipData = relationship.getSingleData().get();
    Assert.assertNotNull(relationshipData);
    Assert.assertEquals("3", relationshipData.getId());
    Assert.assertEquals("projects", relationshipData.getType());
    Assert.assertTrue(document.getIncluded().isEmpty());
}
Also used : Project(io.crnk.core.mock.models.Project) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) LazyTask(io.crnk.core.mock.models.LazyTask) Task(io.crnk.core.mock.models.Task) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) LazyTask(io.crnk.core.mock.models.LazyTask) Document(io.crnk.core.engine.document.Document) Test(org.junit.Test)

Aggregations

LazyTask (io.crnk.core.mock.models.LazyTask)6 Document (io.crnk.core.engine.document.Document)5 Relationship (io.crnk.core.engine.document.Relationship)5 Resource (io.crnk.core.engine.document.Resource)5 Project (io.crnk.core.mock.models.Project)5 Test (org.junit.Test)5 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)4 Task (io.crnk.core.mock.models.Task)3 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 List (java.util.List)1