Search in sources :

Example 36 with Project

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);
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) Test(org.junit.Test)

Example 37 with Project

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, "");
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 38 with Project

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);
}
Also used : Project(io.crnk.core.mock.models.Project) FancyProject(io.crnk.core.mock.models.FancyProject) ResourceField(io.crnk.core.engine.information.resource.ResourceField) Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) FancyProject(io.crnk.core.mock.models.FancyProject) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) RelationshipRepositoryAdapter(io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter) Before(org.junit.Before)

Example 39 with Project

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;
}
Also used : Project(io.crnk.core.mock.models.Project) Relation(io.crnk.core.mock.repository.util.Relation) ProjectEager(io.crnk.core.mock.models.ProjectEager)

Example 40 with Project

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;
}
Also used : FancyProject(io.crnk.core.mock.models.FancyProject) Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) FancyProject(io.crnk.core.mock.models.FancyProject) LinkedList(java.util.LinkedList)

Aggregations

Project (io.crnk.core.mock.models.Project)68 Test (org.junit.Test)54 Task (io.crnk.core.mock.models.Task)44 Document (io.crnk.core.engine.document.Document)27 QuerySpec (io.crnk.core.queryspec.QuerySpec)25 Resource (io.crnk.core.engine.document.Resource)24 Response (io.crnk.core.engine.dispatcher.Response)15 Relationship (io.crnk.core.engine.document.Relationship)14 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)14 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)12 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)12 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)11 LazyTask (io.crnk.core.mock.models.LazyTask)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)8 TaskToProjectRepository (io.crnk.core.mock.repository.TaskToProjectRepository)8 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)7 TaskRepository (io.crnk.core.mock.repository.TaskRepository)7 QueryParams (io.crnk.legacy.queryParams.QueryParams)7 ResourceField (io.crnk.core.engine.information.resource.ResourceField)6