use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class UserToProjectRepository method findOneTarget.
@JsonApiFindOneTarget
public Project findOneTarget(Long sourceId, String fieldName, QuerySpec querySpec) {
for (Relation<User> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
project.setId((Long) relation.getTargetId());
return project;
}
}
return null;
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class UserToProjectRepository method findManyTargets.
@JsonApiFindManyTargets
public Iterable<Project> findManyTargets(Long sourceId, String fieldName, QuerySpec querySpec) {
List<Project> projects = new LinkedList<>();
for (Relation<User> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
project.setId((Long) relation.getTargetId());
projects.add(project);
}
}
return projects;
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedResourceRepositoryAdapterTest method onClassWithInvalidSaveShouldThrowException.
@Test(expected = RepositoryMethodException.class)
public void onClassWithInvalidSaveShouldThrowException() throws Exception {
// GIVEN
ResourceRepositoryWithEmptySave repo = new ResourceRepositoryWithEmptySave();
AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.save(new Project());
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedResourceRepositoryAdapterTest method onClassWithSaveShouldReturnValue.
@Test
public void onClassWithSaveShouldReturnValue() throws Exception {
// GIVEN
ResourceRepositoryWithSave repo = spy(ResourceRepositoryWithSave.class);
AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
// WHEN
Project entity = new Project();
Object result = sut.save(entity);
// THEN
verify(repo).save(eq(entity), eq(""));
assertThat(result).isNotNull();
assertThat(((Project) (result)).getId()).isEqualTo(1L);
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class OppositeFowardingRelationshipRepositoryTest method checkFindManyTargets.
@Test
public void checkFindManyTargets() {
ProjectRepository projectRepository = new ProjectRepository();
Project project = new Project();
project.setId(42L);
project.setName("project");
projectRepository.save(project);
TaskRepository taskRepository = new TaskRepository();
Task task = new Task();
task.setId(13L);
task.setName("task");
task.setProject(project);
taskRepository.save(task);
relRepository = new ForwardingRelationshipRepository(Project.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
relRepository.setResourceRegistry(resourceRegistry);
QuerySpec querySpec = new QuerySpec(Task.class);
List<Task> tasks = relRepository.findManyTargets(42L, "tasks", querySpec);
Assert.assertEquals(1, tasks.size());
Assert.assertEquals(13L, tasks.get(0).getId().longValue());
}
Aggregations