Search in sources :

Example 41 with Project

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

the class UserToProjectRepository method findOneTarget.

@JsonApiFindOneTarget
public Project findOneTarget(Long sourceId, String fieldName, QuerySpec querySpec) {
    for (Relation<User> 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.core.mock.models.Project) User(io.crnk.core.mock.models.User)

Example 42 with Project

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

the class UserToProjectRepository method findManyTargets.

@JsonApiFindManyTargets
public Iterable<Project> findManyTargets(Long sourceId, String fieldName, QuerySpec querySpec) {
    List<Project> projects = new LinkedList<>();
    for (Relation<User> 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.core.mock.models.Project) User(io.crnk.core.mock.models.User) LinkedList(java.util.LinkedList)

Example 43 with Project

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

the class AnnotatedResourceRepositoryAdapterTest method onClassWithInvalidSaveShouldThrowException.

@Test(expected = RepositoryMethodException.class)
public void onClassWithInvalidSaveShouldThrowException() throws Exception {
    // GIVEN
    ResourceRepositoryWithEmptySave repo = new ResourceRepositoryWithEmptySave();
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    sut.save(new Project());
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 44 with Project

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

the class AnnotatedResourceRepositoryAdapterTest method onClassWithSaveShouldReturnValue.

@Test
public void onClassWithSaveShouldReturnValue() throws Exception {
    // GIVEN
    ResourceRepositoryWithSave repo = spy(ResourceRepositoryWithSave.class);
    AnnotatedResourceRepositoryAdapter<Project, Long> sut = new AnnotatedResourceRepositoryAdapter<>(repo, parameterProvider);
    // WHEN
    Project entity = new Project();
    Object result = sut.save(entity);
    // THEN
    verify(repo).save(eq(entity), eq(""));
    assertThat(result).isNotNull();
    assertThat(((Project) (result)).getId()).isEqualTo(1L);
}
Also used : Project(io.crnk.core.mock.models.Project) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) Test(org.junit.Test)

Example 45 with Project

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

the class OppositeFowardingRelationshipRepositoryTest method checkFindManyTargets.

@Test
public void checkFindManyTargets() {
    ProjectRepository projectRepository = new ProjectRepository();
    Project project = new Project();
    project.setId(42L);
    project.setName("project");
    projectRepository.save(project);
    TaskRepository taskRepository = new TaskRepository();
    Task task = new Task();
    task.setId(13L);
    task.setName("task");
    task.setProject(project);
    taskRepository.save(task);
    relRepository = new ForwardingRelationshipRepository(Project.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
    relRepository.setResourceRegistry(resourceRegistry);
    QuerySpec querySpec = new QuerySpec(Task.class);
    List<Task> tasks = relRepository.findManyTargets(42L, "tasks", querySpec);
    Assert.assertEquals(1, tasks.size());
    Assert.assertEquals(13L, tasks.get(0).getId().longValue());
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) ForwardingRelationshipRepository(io.crnk.core.repository.foward.ForwardingRelationshipRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

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