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");
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations