Search in sources :

Example 6 with RelationIdTestResource

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

the class OppositeFowardingRelationshipRepositoryTest method checkFindOneTargetFromSingleValue.

@Test
public void checkFindOneTargetFromSingleValue() {
    RelationIdTestResource parent = new RelationIdTestResource();
    parent.setId(2L);
    parent.setName("parent");
    RelationIdTestResource child = new RelationIdTestResource();
    child.setId(3L);
    child.setName("child");
    parent.setTestNested(child);
    testRepository.create(parent);
    testRepository.create(child);
    QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
    Object target = relRepository.findOneTarget(3L, "testNestedOpposite", querySpec);
    Assert.assertNotNull(target);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 7 with RelationIdTestResource

use of io.crnk.core.mock.models.RelationIdTestResource 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 8 with RelationIdTestResource

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

the class ResourceIdControllerTest method checkPost.

private Resource checkPost() throws IOException {
    // GIVEN
    Resource resource = createResource();
    resource.getRelationships().put("testLookupAlways", new Relationship(schedule3Id));
    Document newDocument = createDocument(resource);
    JsonPath postPath = pathBuilder.build("/relationIdTest");
    // WHEN POST
    ResourcePost sut = new ResourcePost(resourceRegistry, new NullPropertiesProvider(), typeParser, objectMapper, documentMapper, modificationFilters);
    Response taskResponse = sut.handle(postPath, emptyTaskQuery, null, newDocument);
    // THEN POST
    assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.CREATED_201);
    Resource createdResource = taskResponse.getDocument().getSingleData().get();
    Assert.assertEquals(resource.getType(), createdResource.getType());
    Assert.assertEquals(resource.getId(), createdResource.getId());
    Assert.assertEquals(resource.getAttributes().get("name"), createdResource.getAttributes().get("name"));
    Relationship relationship = createdResource.getRelationships().get("testLookupAlways");
    Assert.assertTrue(relationship.getData().isPresent());
    Assert.assertEquals(schedule3Id, relationship.getData().get());
    // validate relationship not accessed, only id set => performance
    RelationIdTestResource entity = repository.findOne(1L, new QuerySpec(RelationIdTestResource.class));
    Assert.assertEquals(schedule3.getId(), entity.getTestLookupAlwaysId());
    Assert.assertNull(entity.getTestLookupAlways());
    return createdResource;
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) Document(io.crnk.core.engine.document.Document) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourcePost(io.crnk.core.engine.internal.dispatcher.controller.ResourcePost) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource)

Example 9 with RelationIdTestResource

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

the class ResourceIdControllerTest method checkPatchRelationship.

private void checkPatchRelationship(Resource resource, ResourceIdentifier scheduleId) {
    JsonPath path = pathBuilder.build("/relationIdTest/" + resource.getId() + "/relationships/testLookupAlways");
    Document newDocument = createDocument(scheduleId);
    // WHEN PATCH
    RelationshipsResourcePatch sut = new RelationshipsResourcePatch(resourceRegistry, typeParser, modificationFilters);
    Response taskResponse = sut.handle(path, emptyTaskQuery, null, newDocument);
    // THEN PATCH
    assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.NO_CONTENT_204);
    // validate relationship not accessed, only id set => performance
    RelationIdTestResource entity = repository.findOne(1L, new QuerySpec(RelationIdTestResource.class));
    Assert.assertEquals(scheduleId != null ? Long.parseLong(scheduleId.getId()) : null, entity.getTestLookupAlwaysId());
    Assert.assertNull(entity.getTestLookupAlways());
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) RelationshipsResourcePatch(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePatch) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) Document(io.crnk.core.engine.document.Document) QuerySpec(io.crnk.core.queryspec.QuerySpec) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource)

Example 10 with RelationIdTestResource

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

the class NestedRelationIdLookupTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
    super.setup();
    scheduleRepository = new ScheduleRepositoryImpl();
    schedule = new Schedule();
    schedule.setId(3L);
    schedule.setName("test");
    scheduleRepository.save(schedule);
    testRepository = new RelationIdTestRepository();
    child = new RelationIdTestResource();
    child.setId(1L);
    child.setName("child");
    testRepository.save(child);
    child.setTestSerializeEager(schedule);
}
Also used : ScheduleRepositoryImpl(io.crnk.core.mock.repository.ScheduleRepositoryImpl) RelationIdTestRepository(io.crnk.core.mock.repository.RelationIdTestRepository) Schedule(io.crnk.core.mock.models.Schedule) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Before(org.junit.Before)

Aggregations

RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)16 QuerySpec (io.crnk.core.queryspec.QuerySpec)13 Document (io.crnk.core.engine.document.Document)12 Resource (io.crnk.core.engine.document.Resource)11 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)9 Response (io.crnk.core.engine.dispatcher.Response)3 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)3 Schedule (io.crnk.core.mock.models.Schedule)3 ScheduleRepositoryImpl (io.crnk.core.mock.repository.ScheduleRepositoryImpl)3 Before (org.junit.Before)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 Relationship (io.crnk.core.engine.document.Relationship)2 RelationshipsResourcePatch (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePatch)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 Project (io.crnk.core.mock.models.Project)2 Task (io.crnk.core.mock.models.Task)2 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)2 TaskRepository (io.crnk.core.mock.repository.TaskRepository)2