use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithEmptyAddRelationsShouldThrowException.
@Test(expected = RepositoryMethodException.class)
public void onClassWithEmptyAddRelationsShouldThrowException() throws Exception {
// GIVEN
RelationshipRepositoryWithEmptyAddRelations repo = new RelationshipRepositoryWithEmptyAddRelations();
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.addRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class RepositoryAdapterTest method onClassWithGetLinksInformationShouldInvokeMethod.
@Test
public void onClassWithGetLinksInformationShouldInvokeMethod() throws Exception {
// GIVEN
ResourceRepositoryWithGetLinksInformation repo = spy(ResourceRepositoryWithGetLinksInformation.class);
AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterFactory);
List<Project> resources = Collections.singletonList(new Project());
// WHEN
sut.getLinksInformation(resources, queryAdapter);
// THEN
verify(repo).getLinksInformation(resources, queryParams, "");
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class IncludeLookupSetterInheritanceTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
super.setup();
// get repositories
ResourceRepositoryAdapter taskRepository = resourceRegistry.getEntry(Task.class).getResourceRepository(null);
RelationshipRepositoryAdapter relRepositoryTaskToProject = resourceRegistry.getEntry(Task.class).getRelationshipRepository("projects", null);
ResourceRepositoryAdapter projectRepository = resourceRegistry.getEntry(Project.class).getResourceRepository(null);
// setup test data
ResourceInformation taskInfo = resourceRegistry.getEntry(Task.class).getResourceInformation();
ResourceField includedProjectsField = taskInfo.findRelationshipFieldByName("includedProjects");
QueryAdapter emptyProjectQuery = new QuerySpecAdapter(new QuerySpec(Project.class), resourceRegistry);
QueryAdapter emptyTaskQuery = new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry);
Project project1 = new Project();
project1.setId(3L);
projectRepository.create(project1, emptyProjectQuery);
FancyProject project2 = new FancyProject();
project2.setId(ProjectRepository.FANCY_PROJECT_ID);
projectRepository.create(project2, emptyProjectQuery);
Task task = new Task();
task.setId(1L);
taskRepository.create(task, emptyTaskQuery);
relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project1.getId()), includedProjectsField, emptyProjectQuery);
relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project2.getId()), includedProjectsField, emptyProjectQuery);
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class ProjectToProjectEagerRepository method findOneTarget.
@Override
public ProjectEager findOneTarget(Long sourceId, String fieldName, QueryParams queryParams) {
Map<Relation<Project>, Integer> repo = getRepo();
for (Relation<Project> relation : repo.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
ProjectEager task = new ProjectEager();
task.setId((Long) relation.getTargetId());
return task;
}
}
return null;
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findManyTargets.
@Override
public Iterable<Project> findManyTargets(Long sourceId, String fieldName, QueryParams queryParams) {
List<Project> projects = new LinkedList<>();
for (Relation<Task> relation : getRepo().keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
if (relation.getTargetId().equals(ProjectRepository.FANCY_PROJECT_ID)) {
project = new FancyProject();
}
project.setId((Long) relation.getTargetId());
projects.add(project);
}
}
return projects;
}
Aggregations