Search in sources :

Example 1 with Project

use of io.crnk.test.mock.models.Project 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 Project

use of io.crnk.test.mock.models.Project 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 Project

use of io.crnk.test.mock.models.Project 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());
		*/
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 4 with Project

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

the class RelationIdClientTest method checkPost.

private Schedule checkPost() {
    project = new Project();
    project.setName("myProject");
    project = projectRepo.create(project);
    Schedule schedule = new Schedule();
    schedule.setId(1L);
    schedule.setName("mySchedule");
    schedule.setProjectId(project.getId());
    schedule.setProjectIds(Arrays.asList(project.getId()));
    Schedule savedSchedule = scheduleRepo.create(schedule);
    Schedule serverSchedule = ScheduleRepositoryImpl.schedules.get(1L);
    Assert.assertEquals(project.getId(), serverSchedule.getProjectId());
    Assert.assertEquals(1, serverSchedule.getProjectIds().size());
    Assert.assertEquals(project.getId(), serverSchedule.getProjectIds().get(0));
    Assert.assertNull(serverSchedule.getProject());
    Assert.assertNotSame(schedule, savedSchedule);
    Assert.assertEquals(project.getId(), savedSchedule.getProjectId());
    Assert.assertEquals(1, savedSchedule.getProjectIds().size());
    return savedSchedule;
}
Also used : Project(io.crnk.test.mock.models.Project) Schedule(io.crnk.test.mock.models.Schedule)

Example 5 with Project

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

the class RelationIdClientTest method checkFindWithoutInclusion.

private void checkFindWithoutInclusion(Schedule schedule) {
    QuerySpec querySpec = new QuerySpec(Schedule.class);
    Schedule foundSchedule = scheduleRepo.findOne(schedule.getId(), querySpec);
    Assert.assertEquals(project.getId(), foundSchedule.getProjectId());
    Assert.assertNull(foundSchedule.getProject());
    Assert.assertEquals(1, foundSchedule.getProjectIds().size());
    Assert.assertEquals(project.getId(), foundSchedule.getProjectIds().get(0));
    Assert.assertNotNull(foundSchedule.getProjects());
    // TODO list should contain proxies in the future
    List<Project> projects = foundSchedule.getProjects();
    Assert.assertEquals(1, projects.size());
    // not initialized, id-only
    Assert.assertNull(projects.get(0).getName());
}
Also used : Project(io.crnk.test.mock.models.Project) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Aggregations

Project (io.crnk.test.mock.models.Project)17 Task (io.crnk.test.mock.models.Task)12 Test (org.junit.Test)7 QuerySpec (io.crnk.core.queryspec.QuerySpec)6 Schedule (io.crnk.test.mock.models.Schedule)3 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)2 QueryParams (io.crnk.legacy.queryParams.QueryParams)2 Before (org.junit.Before)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)1 ProjectLinks (io.crnk.test.mock.models.Project.ProjectLinks)1 ProjectMeta (io.crnk.test.mock.models.Project.ProjectMeta)1 TaskSubType (io.crnk.test.mock.models.TaskSubType)1 ProjectRepository (io.crnk.test.mock.repository.ProjectRepository)1 ProjectsLinksInformation (io.crnk.test.mock.repository.ProjectRepository.ProjectsLinksInformation)1 ProjectsMetaInformation (io.crnk.test.mock.repository.ProjectRepository.ProjectsMetaInformation)1 TaskRepository (io.crnk.test.mock.repository.TaskRepository)1 Serializable (java.io.Serializable)1 JsonFluentAssert (net.javacrumbs.jsonunit.fluent.JsonFluentAssert)1 Span (org.springframework.cloud.sleuth.Span)1