Search in sources :

Example 36 with Task

use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.

the class ModuleClientTest method test.

@Test
public void test() {
    ResourceRepositoryV2<Task, Long> taskRepo = client.getRepositoryForType(Task.class);
    Task task = new Task();
    task.setId(1L);
    task.setName("task");
    taskRepo.create(task);
    List<Task> tasks = taskRepo.findAll(new QuerySpec(Task.class));
    Assert.assertEquals(1, tasks.size());
    Mockito.verify(testModule, Mockito.times(1)).setupModule(Mockito.any(ModuleContext.class));
    Mockito.verify(testModule, Mockito.times(1)).setHttpAdapter(Mockito.eq(client.getHttpAdapter()));
    Mockito.verify(adapterListener, Mockito.times(1)).onBuild(Mockito.any(Builder.class));
}
Also used : Task(io.crnk.test.mock.models.Task) Builder(okhttp3.OkHttpClient.Builder) ModuleContext(io.crnk.core.module.Module.ModuleContext) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Example 37 with Task

use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testSortDesc.

@Test
public void testSortDesc() {
    for (int i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(Long.valueOf(i));
        task.setName("task" + i);
        taskRepo.create(task);
    }
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addSort(new SortSpec(Arrays.asList("name"), Direction.DESC));
    List<Task> tasks = taskRepo.findAll(querySpec);
    Assert.assertEquals(5, tasks.size());
    for (int i = 0; i < 5; i++) {
        Assert.assertEquals("task" + i, tasks.get(4 - i).getName());
    }
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 38 with Task

use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testSortAsc.

@Test
public void testSortAsc() {
    for (int i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(Long.valueOf(i));
        task.setName("task" + i);
        taskRepo.create(task);
    }
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addSort(new SortSpec(Arrays.asList("name"), Direction.ASC));
    List<Task> tasks = taskRepo.findAll(querySpec);
    Assert.assertEquals(5, tasks.size());
    for (int i = 0; i < 5; i++) {
        Assert.assertEquals("task" + i, tasks.get(i).getName());
    }
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 39 with Task

use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testFindEmpty.

@Test
public void testFindEmpty() {
    List<Task> tasks = taskRepo.findAll(new QuerySpec(Task.class));
    Assert.assertTrue(tasks.isEmpty());
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 40 with Task

use of io.crnk.test.mock.models.Task in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testDelete.

@Test
public void testDelete() {
    Task task = new Task();
    task.setId(1L);
    task.setName("test");
    taskRepo.create(task);
    taskRepo.delete(1L);
    List<Task> tasks = taskRepo.findAll(new QuerySpec(Task.class));
    Assert.assertEquals(0, tasks.size());
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

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