use of io.crnk.test.mock.models.Project in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findOneTarget.
@Override
public Project findOneTarget(Long sourceId, String fieldName, QuerySpec queryParams) {
for (Relation<Task> 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.test.mock.models.Project in project crnk-framework by crnk-project.
the class ProjectToTaskRepository method findManyTargets.
@Override
public ResourceList<Task> findManyTargets(Long sourceId, String fieldName, QuerySpec queryParams) {
DefaultResourceList<Task> tasks = new DefaultResourceList<>();
for (Relation<Project> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Task task = taskRepo.findOne((long) relation.getTargetId(), null);
Assert.assertNotNull(task);
tasks.add(task);
}
}
return tasks;
}
use of io.crnk.test.mock.models.Project in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testAddSetRemoveRelations.
@Test
public void testAddSetRemoveRelations() {
Project project0 = new Project();
project0.setId(1L);
project0.setName("project0");
projectRepo.create(project0);
Project project1 = new Project();
project1.setId(2L);
project1.setName("project1");
projectRepo.create(project1);
Task task = new Task();
task.setId(3L);
task.setName("test");
taskRepo.create(task);
relRepo.addRelations(task, Arrays.asList(project0.getId(), project1.getId()), "projects");
List<Project> relProjects = relRepo.findManyTargets(task.getId(), "projects", new QuerySpec(Task.class));
Assert.assertEquals(2, relProjects.size());
relRepo.setRelations(task, Arrays.asList(project1.getId()), "projects");
relProjects = relRepo.findManyTargets(task.getId(), "projects", new QuerySpec(Task.class));
Assert.assertEquals(1, relProjects.size());
Assert.assertEquals(project1.getId(), relProjects.get(0).getId());
// TODO HTTP DELETE method with payload not supported? at least in
// Jersey
/*
relRepo.removeRelations(task, Arrays.asList(project1.getId()),
"projects");
relProjects = relRepo.findManyTargets(task.getId(), "projects", new QuerySpec(Task.class));
Assert.assertEquals(0, relProjects.size());
*/
}
use of io.crnk.test.mock.models.Project in project crnk-framework by crnk-project.
the class RelationIdClientTest method checkPost.
private Schedule checkPost() {
project = new Project();
project.setName("myProject");
project = projectRepo.create(project);
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("mySchedule");
schedule.setProjectId(project.getId());
schedule.setProjectIds(Arrays.asList(project.getId()));
Schedule savedSchedule = scheduleRepo.create(schedule);
Schedule serverSchedule = ScheduleRepositoryImpl.schedules.get(1L);
Assert.assertEquals(project.getId(), serverSchedule.getProjectId());
Assert.assertEquals(1, serverSchedule.getProjectIds().size());
Assert.assertEquals(project.getId(), serverSchedule.getProjectIds().get(0));
Assert.assertNull(serverSchedule.getProject());
Assert.assertNotSame(schedule, savedSchedule);
Assert.assertEquals(project.getId(), savedSchedule.getProjectId());
Assert.assertEquals(1, savedSchedule.getProjectIds().size());
return savedSchedule;
}
use of io.crnk.test.mock.models.Project in project crnk-framework by crnk-project.
the class RelationIdClientTest method checkFindWithoutInclusion.
private void checkFindWithoutInclusion(Schedule schedule) {
QuerySpec querySpec = new QuerySpec(Schedule.class);
Schedule foundSchedule = scheduleRepo.findOne(schedule.getId(), querySpec);
Assert.assertEquals(project.getId(), foundSchedule.getProjectId());
Assert.assertNull(foundSchedule.getProject());
Assert.assertEquals(1, foundSchedule.getProjectIds().size());
Assert.assertEquals(project.getId(), foundSchedule.getProjectIds().get(0));
Assert.assertNotNull(foundSchedule.getProjects());
// TODO list should contain proxies in the future
List<Project> projects = foundSchedule.getProjects();
Assert.assertEquals(1, projects.size());
// not initialized, id-only
Assert.assertNull(projects.get(0).getName());
}
Aggregations