use of io.crnk.test.mock.models.Task 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.Task in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testSaveRelationWithCreate.
@Test
public void testSaveRelationWithCreate() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
scheduleRepo.create(schedule);
Task task = new Task();
task.setId(2L);
task.setName("test");
task.setSchedule(schedule);
taskRepo.create(task);
// check relationship available
Task savedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNotNull(savedTask.getSchedule());
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testSetRelation.
@Test
public void testSetRelation() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
scheduleRepo.create(schedule);
Task task = new Task();
task.setId(2L);
task.setName("test");
taskRepo.create(task);
relRepo.setRelation(task, schedule.getId(), "schedule");
Schedule relSchedule = taskScheduleRepo.findOneTarget(task.getId(), "schedule", new QuerySpec(Schedule.class));
Assert.assertNotNull(relSchedule);
Assert.assertEquals(schedule.getId(), relSchedule.getId());
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testNullNonLazyRelationWithSave.
@Test
public void testNullNonLazyRelationWithSave() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
scheduleRepo.create(schedule);
Task task = new Task();
task.setId(2L);
task.setName("test");
task.setSchedule(schedule);
taskRepo.create(task);
Task savedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNotNull(savedTask.getSchedule());
// null
savedTask.setSchedule(null);
taskRepo.save(savedTask);
// relation must be null
Task updatedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNull(updatedTask.getSchedule());
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testUpdate.
public void testUpdate(boolean pushAlways) {
final List<String> methods = new ArrayList<>();
final List<String> paths = new ArrayList<>();
final Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
methods.add(request.method());
paths.add(request.url().encodedPath());
return chain.proceed(request);
}
};
HttpAdapter httpAdapter = client.getHttpAdapter();
if (httpAdapter instanceof OkHttpAdapter) {
((OkHttpAdapter) httpAdapter).addListener(new OkHttpAdapterListener() {
@Override
public void onBuild(Builder builder) {
builder.addInterceptor(interceptor);
}
});
}
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
Task savedTask = taskRepo.findOne(1L, new QuerySpec(Task.class));
Assert.assertNotNull(savedTask);
// perform update
task.setName("updatedName");
taskRepo.save(task);
// check updated
savedTask = taskRepo.findOne(1L, new QuerySpec(Task.class));
Assert.assertNotNull(savedTask);
Assert.assertEquals("updatedName", task.getName());
if (httpAdapter instanceof OkHttpAdapter) {
// check HTTP handling
Assert.assertEquals(4, methods.size());
Assert.assertEquals(4, paths.size());
Assert.assertEquals("POST", methods.get(0));
Assert.assertEquals("GET", methods.get(1));
if (pushAlways) {
Assert.assertEquals("POST", methods.get(2));
Assert.assertEquals("/tasks", paths.get(2));
} else {
Assert.assertEquals("PATCH", methods.get(2));
Assert.assertEquals("/tasks/1", paths.get(2));
}
Assert.assertEquals("GET", methods.get(3));
Assert.assertEquals("/tasks", paths.get(0));
Assert.assertEquals("/tasks/1", paths.get(1));
Assert.assertEquals("/tasks/1", paths.get(3));
}
}
Aggregations