Search in sources :

Example 61 with Project

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

Example 62 with Project

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

the class DocumentMapperTest method testRelationshipLazyMultiValued.

@Test
public void testRelationshipLazyMultiValued() {
    LazyTask task = createLazyTask(2);
    Project project1 = createProject(3, "sample project");
    Project project2 = createProject(4, "sample project");
    task.setProjects(Arrays.asList(project1, project2));
    Document document = mapper.toDocument(toResponse(task), createAdapter(Task.class));
    Resource resource = document.getSingleData().get();
    Assert.assertEquals("2", resource.getId());
    Relationship relationship = resource.getRelationships().get("projects");
    Assert.assertNotNull(relationship);
    Nullable<List<ResourceIdentifier>> relationshipData = relationship.getCollectionData();
    Assert.assertFalse(relationshipData.isPresent());
    Assert.assertTrue(document.getIncluded().isEmpty());
}
Also used : Project(io.crnk.core.mock.models.Project) 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) List(java.util.List) LazyTask(io.crnk.core.mock.models.LazyTask) Document(io.crnk.core.engine.document.Document) Test(org.junit.Test)

Example 63 with Project

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

the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithRemoveRelationsShouldAddValue.

@Test
public void onClassWithRemoveRelationsShouldAddValue() throws Exception {
    // GIVEN
    RelationshipRepositoryWithRemoveRelations repo = spy(RelationshipRepositoryWithRemoveRelations.class);
    AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
    Task task = new Task();
    // WHEN
    sut.removeRelations(task, Collections.singleton(1L), "project", queryAdapter);
    // THEN
    verify(repo).removeRelations(eq(task), eq(Collections.singleton(1L)), eq("project"));
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) Test(org.junit.Test)

Example 64 with Project

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

the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithoutAddRelationsShouldThrowException.

@Test(expected = RepositoryAnnotationNotFoundException.class)
public void onClassWithoutAddRelationsShouldThrowException() throws Exception {
    // GIVEN
    RelationshipRepositoryWithoutAnyMethods repo = new RelationshipRepositoryWithoutAnyMethods();
    AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    sut.addRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) Test(org.junit.Test)

Example 65 with Project

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

the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithEmptySetRelationsShouldThrowException.

@Test(expected = RepositoryMethodException.class)
public void onClassWithEmptySetRelationsShouldThrowException() throws Exception {
    // GIVEN
    RelationshipRepositoryWithEmptySetRelations repo = new RelationshipRepositoryWithEmptySetRelations();
    AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    sut.setRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) Test(org.junit.Test)

Aggregations

Project (io.crnk.core.mock.models.Project)68 Test (org.junit.Test)54 Task (io.crnk.core.mock.models.Task)44 Document (io.crnk.core.engine.document.Document)27 QuerySpec (io.crnk.core.queryspec.QuerySpec)25 Resource (io.crnk.core.engine.document.Resource)24 Response (io.crnk.core.engine.dispatcher.Response)15 Relationship (io.crnk.core.engine.document.Relationship)14 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)14 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)12 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)12 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)11 LazyTask (io.crnk.core.mock.models.LazyTask)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)8 TaskToProjectRepository (io.crnk.core.mock.repository.TaskToProjectRepository)8 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)7 TaskRepository (io.crnk.core.mock.repository.TaskRepository)7 QueryParams (io.crnk.legacy.queryParams.QueryParams)7 ResourceField (io.crnk.core.engine.information.resource.ResourceField)6