Search in sources :

Example 41 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testIdAccess.

@Test
public void testIdAccess() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField idField = info.getIdField();
    Assert.assertTrue(idField.getAccess().isPostable());
    Assert.assertFalse(idField.getAccess().isPatchable());
    Assert.assertTrue(idField.getAccess().isSortable());
    Assert.assertTrue(idField.getAccess().isFilterable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 42 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField 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 43 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField 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 44 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField 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)

Example 45 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class DefaultResourceInformationProviderTest method checkJsonPropertyAccessPolicy.

@Test
public void checkJsonPropertyAccessPolicy() throws Exception {
    ResourceInformation resourceInformation = resourceInformationProvider.build(JsonIgnoreTestResource.class);
    ResourceField defaultAttribute = resourceInformation.findAttributeFieldByName("defaultAttribute");
    ResourceField readOnlyAttribute = resourceInformation.findAttributeFieldByName("readOnlyAttribute");
    ResourceField readWriteAttribute = resourceInformation.findAttributeFieldByName("readWriteAttribute");
    ResourceField writeOnlyAttribute = resourceInformation.findAttributeFieldByName("writeOnlyAttribute");
    Assert.assertTrue(defaultAttribute.getAccess().isPatchable());
    Assert.assertTrue(defaultAttribute.getAccess().isPostable());
    Assert.assertFalse(readOnlyAttribute.getAccess().isPatchable());
    Assert.assertFalse(readOnlyAttribute.getAccess().isPostable());
    Assert.assertTrue(readOnlyAttribute.getAccess().isReadable());
    Assert.assertTrue(readWriteAttribute.getAccess().isPatchable());
    Assert.assertTrue(readWriteAttribute.getAccess().isPostable());
    Assert.assertTrue(readWriteAttribute.getAccess().isReadable());
    Assert.assertTrue(writeOnlyAttribute.getAccess().isPatchable());
    Assert.assertTrue(writeOnlyAttribute.getAccess().isPostable());
    Assert.assertFalse(writeOnlyAttribute.getAccess().isReadable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Aggregations

ResourceField (io.crnk.core.engine.information.resource.ResourceField)109 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)75 Test (org.junit.Test)41 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)36 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)13 QuerySpec (io.crnk.core.queryspec.QuerySpec)11 ArrayList (java.util.ArrayList)9 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)8 Response (io.crnk.core.engine.dispatcher.Response)8 Resource (io.crnk.core.engine.document.Resource)8 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)8 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 HashSet (java.util.HashSet)8 Document (io.crnk.core.engine.document.Document)7 Task (io.crnk.core.mock.models.Task)7 Serializable (java.io.Serializable)7 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6