use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class BasicSpringBootTest method testRelationshipInclusion.
@Test
public void testRelationshipInclusion() {
Project project = new Project();
ProjectRepository projectRepository = new ProjectRepository();
projectRepository.save(project);
Task task = new Task();
task.setProject(project);
TaskRepository taskRepository = new TaskRepository();
taskRepository.save(task);
RestTemplate testRestTemplate = new RestTemplate();
ResponseEntity<String> response = testRestTemplate.getForEntity("http://localhost:" + this.port + "/api/tasks?include[tasks]=schedule%2Cproject", String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
JsonFluentAssert included = assertThatJson(response.getBody()).node("included");
included.isArray().ofLength(1);
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class SleuthModuleTest method testError.
@Test
public void testError() {
Task task = new Task();
task.setId(13L);
try {
taskRepo.create(task);
} catch (Exception e) {
// ok
}
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
assertBinaryAnnotation(callSpan, "http.status_code", "500");
// check server local span
Assert.assertEquals(1, reportedSpans.spans.size());
Span repositorySpan = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:post:/tasks/13", repositorySpan.getName());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?");
assertBinaryAnnotation(repositorySpan, "crnk.status", "EXCEPTION");
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class RestTemplateClientTest method testUpdate.
@Test
public void testUpdate() {
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);
}
};
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());
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class RestTemplateClientTest method testFindEmpty.
@Test
public void testFindEmpty() {
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "doesNotExist"));
List<Task> tasks = taskRepo.findAll(querySpec);
Assert.assertTrue(tasks.isEmpty());
}
use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.
the class RestTemplateClientTest method testCreateAndFind.
@Test
public void testCreateAndFind() {
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
// check retrievable with findAll
List<Task> tasks = taskRepo.findAll(new QuerySpec(Task.class));
Assert.assertEquals(1, tasks.size());
Task savedTask = tasks.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
// check retrievable with findAll(ids)
tasks = taskRepo.findAll(Arrays.asList(1L), new QuerySpec(Task.class));
Assert.assertEquals(1, tasks.size());
savedTask = tasks.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
// check retrievable with findOne
savedTask = taskRepo.findOne(1L, new QuerySpec(Task.class));
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
}
Aggregations