Search in sources :

Example 46 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ImplicitOwnerBasedRelationshipRepositoryTest 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 = new ImplicitOwnerBasedRelationshipRepository(RelationIdTestResource.class, Schedule.class);
    relRepository.setResourceRegistry(resourceRegistry);
    taskProjectRepository = new ImplicitOwnerBasedRelationshipRepository(Task.class, Project.class);
    taskProjectRepository.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) TaskRepository(io.crnk.core.mock.repository.TaskRepository) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ScheduleRepositoryImpl(io.crnk.core.mock.repository.ScheduleRepositoryImpl) Project(io.crnk.core.mock.models.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ImplicitOwnerBasedRelationshipRepository(io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository) 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 47 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ImplicitOwnerBasedRelationshipRepositoryTest method testSourceOnlyClassConstructor.

@Test
public void testSourceOnlyClassConstructor() {
    RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
    ResourceField otherField = entry.getResourceInformation().findFieldByUnderlyingName("testNested");
    ResourceField relField = entry.getResourceInformation().findRelationshipFieldByName("testSerializeEager");
    ImplicitOwnerBasedRelationshipRepository repo = new ImplicitOwnerBasedRelationshipRepository(RelationIdTestResource.class);
    repo.setResourceRegistry(resourceRegistry);
    Assert.assertTrue(repo.getMatcher().matches(otherField));
    Assert.assertTrue(repo.getMatcher().matches(relField));
    relRepository.setRelation(resource, 3L, "testSerializeEager");
    Assert.assertEquals(3L, resource.getTestSerializeEagerId().longValue());
    Assert.assertNull(resource.getTestSerializeEager());
    Assert.assertSame(schedule3, relRepository.findOneTarget(resource.getId(), "testSerializeEager", new QuerySpec(Schedule.class)));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ImplicitOwnerBasedRelationshipRepository(io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 48 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ImplicitOwnerBasedRelationshipRepositoryTest method testSourceTargetResourceTypeConstructor.

@Test
public void testSourceTargetResourceTypeConstructor() {
    RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
    ResourceField otherField = entry.getResourceInformation().findFieldByUnderlyingName("testNested");
    ResourceField relField = entry.getResourceInformation().findRelationshipFieldByName("testSerializeEager");
    ImplicitOwnerBasedRelationshipRepository repo = new ImplicitOwnerBasedRelationshipRepository("relationIdTest", "schedules");
    repo.setResourceRegistry(resourceRegistry);
    Assert.assertFalse(repo.getMatcher().matches(otherField));
    Assert.assertTrue(repo.getMatcher().matches(relField));
    relRepository.setRelation(resource, 3L, "testSerializeEager");
    Assert.assertEquals(3L, resource.getTestSerializeEagerId().longValue());
    Assert.assertNull(resource.getTestSerializeEager());
    Assert.assertSame(schedule3, relRepository.findOneTarget(resource.getId(), "testSerializeEager", new QuerySpec(Schedule.class)));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ImplicitOwnerBasedRelationshipRepository(io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 49 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class TotalBasedPagedLinksInformationTest method setup.

@Before
public void setup() {
    TotalResourceCountTestRepository.clear();
    super.setup();
    RegistryEntry registryEntry = resourceRegistry.findEntry(Task.class);
    TotalResourceCountTestRepository repo = (TotalResourceCountTestRepository) registryEntry.getResourceRepository(null).getResourceRepository();
    adapter = registryEntry.getResourceRepository(null);
    QueryAdapter queryAdapter = new QuerySpecAdapter(querySpec(), resourceRegistry);
    for (long i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(i);
        task.setName("myTask");
        adapter.create(task, queryAdapter);
    }
}
Also used : Task(io.crnk.core.mock.models.Task) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Before(org.junit.Before)

Example 50 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ResourceRegistryTest method onExistingResourceShouldReturnUrl.

@Test
public void onExistingResourceShouldReturnUrl() {
    Task task = new Task();
    task.setId(1L);
    ResourceField idField = new ResourceFieldImpl("id", "id", ResourceFieldType.ID, Long.class, Long.class, null);
    ResourceField valueField = new ResourceFieldImpl("value", "value", ResourceFieldType.RELATIONSHIP, String.class, String.class, "projects");
    ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, Arrays.asList(idField, valueField), new OffsetLimitPagingBehavior());
    RegistryEntry registryEntry = new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL)));
    resourceRegistry.addEntry(Task.class, registryEntry);
    String resourceUrl = resourceRegistry.getResourceUrl(task);
    assertThat(resourceUrl).isEqualTo(TEST_MODELS_URL + "/tasks/1");
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceFieldImpl(io.crnk.core.engine.internal.information.resource.ResourceFieldImpl) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6