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());
}
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());
}
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"));
}
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);
}
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);
}
Aggregations