Search in sources :

Example 6 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class OppositeFowardingRelationshipRepositoryTest method checkFindTargetWithNullRelationshipValue.

@Test
public void checkFindTargetWithNullRelationshipValue() {
    TaskRepository taskRepository = new TaskRepository();
    Task task = new Task();
    task.setId(13L);
    task.setName("task");
    taskRepository.save(task);
    Task nullIdTask = new Task();
    ProjectRepository projectRepository = new ProjectRepository();
    Project project = new Project();
    project.setId(42L);
    project.setName("project");
    project.setTasks(Arrays.asList(nullIdTask));
    projectRepository.save(project);
    relRepository = new ForwardingRelationshipRepository(Task.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
    relRepository.setResourceRegistry(resourceRegistry);
    QuerySpec querySpec = new QuerySpec(Task.class);
    try {
        relRepository.findOneTarget(13L, "project", querySpec);
        Assert.fail();
    } catch (IllegalStateException e) {
        Assert.assertTrue(e.getMessage().contains("id is null for"));
    }
}
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)

Example 7 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository 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)

Example 8 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class OwnerFowardingRelationshipRepositoryTest method setup.

@Before
public void setup() {
    MockRepositoryUtil.clear();
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
    relRepository = (ForwardingRelationshipRepository) entry.getRelationshipRepository("testSerializeEager", null).getRelationshipRepository();
    RelationshipMatcher taskProjectMatcher = new RelationshipMatcher().rule().source(Task.class).target(Project.class).add();
    taskProjectRepository = new ForwardingRelationshipRepository(Task.class, taskProjectMatcher, ForwardingDirection.OWNER, ForwardingDirection.OWNER);
    taskProjectRepository.setResourceRegistry(resourceRegistry);
    projectTaskRepository = new ForwardingRelationshipRepository(Project.class, taskProjectMatcher, ForwardingDirection.OWNER, ForwardingDirection.OWNER);
    projectTaskRepository.setResourceRegistry(resourceRegistry);
    testRepository = (RelationIdTestRepository) entry.getResourceRepository().getResourceRepository();
    testRepository.setResourceRegistry(resourceRegistry);
    resource = new RelationIdTestResource();
    resource.setId(2L);
    resource.setName("relationId");
    testRepository.create(resource);
    scheduleRepository = new ScheduleRepositoryImpl();
    schedule3 = new Schedule();
    schedule3.setId(3L);
    schedule3.setName("schedule");
    scheduleRepository.create(schedule3);
    for (int i = 0; i < 10; i++) {
        schedule = new Schedule();
        schedule.setId(4L + i);
        schedule.setName("schedule");
        scheduleRepository.create(schedule);
        projectRepository = new ProjectRepository();
        project = new Project();
        project.setId(42L + i);
        project.setName("project");
        projectRepository.save(project);
        taskRepository = new TaskRepository();
        task = new Task();
        task.setId(13L + i);
        task.setName("task");
        taskRepository.save(task);
    }
}
Also used : 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) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) RelationshipMatcher(io.crnk.core.repository.RelationshipMatcher) ScheduleRepositoryImpl(io.crnk.core.mock.repository.ScheduleRepositoryImpl) Project(io.crnk.core.mock.models.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) Schedule(io.crnk.core.mock.models.Schedule) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Before(org.junit.Before)

Example 9 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class ResourcePostTest method onNewResourcesAndRelationshipShouldPersistThoseData.

@Test
public void onNewResourcesAndRelationshipShouldPersistThoseData() throws Exception {
    // GIVEN
    Document newProjectBody = new Document();
    Resource data = createProject();
    newProjectBody.setData(Nullable.of((Object) data));
    JsonPath projectPath = pathBuilder.build("/projects");
    ResourcePost sut = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
    // WHEN
    Response projectResponse = sut.handle(projectPath, emptyProjectQuery, null, newProjectBody);
    // THEN
    assertThat(projectResponse.getHttpStatus()).isEqualTo(HttpStatus.CREATED_201);
    assertThat(projectResponse.getDocument().getData().get()).isExactlyInstanceOf(Resource.class);
    assertThat(projectResponse.getDocument().getSingleData().get().getType()).isEqualTo("projects");
    Resource persistedProject = projectResponse.getDocument().getSingleData().get();
    assertThat(persistedProject.getId()).isNotNull();
    assertThat(persistedProject.getAttributes().get("name").asText()).isEqualTo("sample project");
    assertThat(persistedProject.getAttributes().get("data").get("data").asText()).isEqualTo("asd");
    Long projectId = Long.parseLong(projectResponse.getDocument().getSingleData().get().getId());
    Mockito.verify(modificationFilter, Mockito.times(1)).modifyAttribute(Mockito.any(), Mockito.any(ResourceField.class), Mockito.eq("data"), Mockito.any());
    /* ------- */
    // GIVEN
    Document newTasksBody = new Document();
    newTasksBody.setData(Nullable.of((Object) createTask()));
    newTasksBody.getSingleData().get().getRelationships().put("project", new Relationship(new ResourceIdentifier(projectId.toString(), "projects")));
    JsonPath taskPath = pathBuilder.build("/tasks");
    // WHEN
    Response taskResponse = sut.handle(taskPath, emptyTaskQuery, null, newTasksBody);
    // THEN
    assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.CREATED_201);
    assertThat(taskResponse.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
    String taskId = taskResponse.getDocument().getSingleData().get().getId();
    assertThat(taskId).isNotNull();
    assertThat(taskResponse.getDocument().getSingleData().get().getAttributes().get("name").asText()).isEqualTo("sample task");
    TaskRepository taskRepository = new TaskRepository();
    Task persistedTask = taskRepository.findOne(Long.parseLong(taskId), null);
    assertThat(persistedTask.getProject().getId()).isEqualTo(projectId);
}
Also used : Task(io.crnk.core.mock.models.Task) TaskRepository(io.crnk.core.mock.repository.TaskRepository) Resource(io.crnk.core.engine.document.Resource) Document(io.crnk.core.engine.document.Document) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) ResourcePost(io.crnk.core.engine.internal.dispatcher.controller.ResourcePost) Response(io.crnk.core.engine.dispatcher.Response) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 10 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class ResourceFieldContributorTest method setup.

@Before
public void setup() {
    MockRepositoryUtil.clear();
    contributedRepository = Mockito.spy(new ContributorRelationshipRepository());
    SimpleModule testModule = new SimpleModule("test");
    testModule.addRepository(new TaskRepository());
    testModule.addRepository(new ProjectRepository());
    testModule.addRepository(new ProjectToTaskRepository());
    testModule.addRepository(contributedRepository);
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new TestServiceDiscovery());
    boot.addModule(testModule);
    boot.boot();
}
Also used : ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) CrnkBoot(io.crnk.core.boot.CrnkBoot) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TestServiceDiscovery(io.crnk.core.module.discovery.TestServiceDiscovery) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Aggregations

TaskRepository (io.crnk.core.mock.repository.TaskRepository)13 Task (io.crnk.core.mock.models.Task)10 Test (org.junit.Test)9 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)8 Project (io.crnk.core.mock.models.Project)7 ForwardingRelationshipRepository (io.crnk.core.repository.foward.ForwardingRelationshipRepository)6 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 Before (org.junit.Before)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)3 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)3 Response (io.crnk.core.engine.dispatcher.Response)2 Document (io.crnk.core.engine.document.Document)2 Relationship (io.crnk.core.engine.document.Relationship)2 Resource (io.crnk.core.engine.document.Resource)2 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)2 Schedule (io.crnk.core.mock.models.Schedule)2