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());
}
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)));
}
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)));
}
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");
}
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());
}
Aggregations