Search in sources :

Example 11 with Project

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

the class SleuthModuleTest method testFindTargets.

@Test
public void testFindTargets() {
    RelationshipRepositoryV2<Project, Serializable, Task, Serializable> relRepo = client.getQuerySpecRepository(Project.class, Task.class);
    relRepo.findManyTargets(123L, "tasks", new QuerySpec(Task.class));
    // 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("get", callSpan.getName());
    Assert.assertTrue(callSpan.toString().contains("\"cs\""));
    Assert.assertTrue(callSpan.toString().contains("\"cr\""));
    // check server local span
    Assert.assertEquals(2, reportedSpans.spans.size());
    Span repositorySpan0 = reportedSpans.spans.get(0);
    Assert.assertEquals("crnk:get:/tasks", repositorySpan0.getName());
    Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
    assertBinaryAnnotation(repositorySpan0, "lc", "crnk");
    assertBinaryAnnotation(repositorySpan0, "crnk.results", "0");
    assertBinaryAnnotation(repositorySpan0, "crnk.status", "OK");
    Span repositorySpan1 = reportedSpans.spans.get(1);
    Assert.assertEquals("crnk:get:/projects/123/tasks", repositorySpan1.getName());
    Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
    assertBinaryAnnotation(repositorySpan1, "lc", "crnk");
    assertBinaryAnnotation(repositorySpan1, "crnk.query", "?");
    assertBinaryAnnotation(repositorySpan1, "crnk.results", "0");
    assertBinaryAnnotation(repositorySpan1, "crnk.status", "OK");
}
Also used : Project(io.crnk.test.mock.models.Project) Serializable(java.io.Serializable) Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with Project

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

the class TaskToProjectRepository method findManyTargets.

@Override
public ResourceList<Project> findManyTargets(Long sourceId, String fieldName, QuerySpec queryParams) {
    DefaultResourceList<Project> projects = new DefaultResourceList<>();
    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());
            projects.add(project);
        }
    }
    return projects;
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList)

Example 13 with Project

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

the class ProjectToTaskRepository method findOneTarget.

@Override
public Task findOneTarget(Long sourceId, String fieldName, QuerySpec queryParams) {
    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);
            return task;
        }
    }
    return null;
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task)

Example 14 with Project

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

the class RelationIdClientTest method checkPatch.

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

Example 15 with Project

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

the class InheritanceClientTest method doTestIncludePoloymorphCollection.

private void doTestIncludePoloymorphCollection(boolean include) {
    QuerySpec querySpec = new QuerySpec(Project.class);
    if (include) {
        querySpec.includeRelation(Arrays.asList("tasks"));
    }
    List<Project> projects = projectRepo.findAll(querySpec);
    Assert.assertEquals(1, projects.size());
    Project project = projects.get(0);
    List<Task> tasks = project.getTasks();
    if (include) {
        Assert.assertFalse(tasks instanceof ObjectProxy);
    } else {
        ObjectProxy proxy = (ObjectProxy) tasks;
        Assert.assertFalse(proxy.isLoaded());
    }
    if (tasks.get(0).getName().equals("baseTask")) {
        Assert.assertEquals("baseTask", tasks.get(0).getName());
        Assert.assertEquals("taskSubType", tasks.get(1).getName());
    } else {
        Assert.assertEquals("baseTask", tasks.get(1).getName());
        Assert.assertEquals("taskSubType", tasks.get(0).getName());
    }
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) ObjectProxy(io.crnk.client.internal.proxy.ObjectProxy) 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