Search in sources :

Example 21 with Task

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);
}
Also used : JsonFluentAssert(net.javacrumbs.jsonunit.fluent.JsonFluentAssert) Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) ProjectRepository(io.crnk.test.mock.repository.ProjectRepository) TaskRepository(io.crnk.test.mock.repository.TaskRepository) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with Task

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");
}
Also used : Task(io.crnk.test.mock.models.Task) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with Task

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());
}
Also used : Task(io.crnk.test.mock.models.Task) ArrayList(java.util.ArrayList) Request(okhttp3.Request) QuerySpec(io.crnk.core.queryspec.QuerySpec) Interceptor(okhttp3.Interceptor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Task

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());
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Task

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());
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (io.crnk.test.mock.models.Task)53 Test (org.junit.Test)42 QuerySpec (io.crnk.core.queryspec.QuerySpec)27 Project (io.crnk.test.mock.models.Project)11 Schedule (io.crnk.test.mock.models.Schedule)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 QueryParams (io.crnk.legacy.queryParams.QueryParams)6 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Resource (io.crnk.core.engine.document.Resource)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 Span (org.springframework.cloud.sleuth.Span)4 SortSpec (io.crnk.core.queryspec.SortSpec)3 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)3 TaskRepository (io.crnk.test.mock.repository.TaskRepository)3 Interceptor (okhttp3.Interceptor)3 Before (org.junit.Before)3 OkHttpAdapter (io.crnk.client.http.okhttp.OkHttpAdapter)2 OkHttpAdapterListener (io.crnk.client.http.okhttp.OkHttpAdapterListener)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2