Search in sources :

Example 1 with Task

use of io.crnk.test.mock.models.Task 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;
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task)

Example 2 with Task

use of io.crnk.test.mock.models.Task 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;
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList)

Example 3 with Task

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

the class ControllerTest method setup.

@Before
public void setup() {
    TaskRepository repo = new TaskRepository();
    Task task = new Task();
    task.setName("test value");
    task.setId(1L);
    repo.save(task);
}
Also used : Task(io.crnk.test.mock.models.Task) TaskRepository(io.crnk.test.mock.repository.TaskRepository) Before(org.junit.Before)

Example 4 with Task

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

the class QuerySpecClientTest 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)

Example 5 with Task

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

the class QuerySpecClientTest method testGeneratedId.

@Test
public void testGeneratedId() {
    Task task = new Task();
    task.setId(null);
    task.setName("test");
    Task savedTask = taskRepo.create(task);
    Assert.assertNotNull(savedTask.getId());
}
Also used : Task(io.crnk.test.mock.models.Task) 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