use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class JpaResourceInformationProviderTest method test.
@Test
public void test() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
ResourceInformation info = builder.build(TestEntity.class);
ResourceField idField = info.getIdField();
assertNotNull(idField);
assertEquals("id", idField.getJsonName());
assertEquals("id", idField.getUnderlyingName());
assertEquals(Long.class, idField.getType());
assertEquals(Long.class, idField.getGenericType());
List<ResourceField> attrFields = new ArrayList<>(info.getAttributeFields());
Collections.sort(attrFields, ResourceFieldComparator.INSTANCE);
assertEquals(5, attrFields.size());
ResourceField embField = attrFields.get(1);
assertEquals(TestEntity.ATTR_embValue, embField.getJsonName());
assertEquals(TestEntity.ATTR_embValue, embField.getUnderlyingName());
assertEquals(TestEmbeddable.class, embField.getType());
assertEquals(TestEmbeddable.class, embField.getGenericType());
Assert.assertTrue(embField.getAccess().isPostable());
Assert.assertTrue(embField.getAccess().isPatchable());
Assert.assertTrue(embField.getAccess().isSortable());
Assert.assertTrue(embField.getAccess().isFilterable());
ArrayList<ResourceField> relFields = new ArrayList<ResourceField>(info.getRelationshipFields());
Collections.sort(relFields, ResourceFieldComparator.INSTANCE);
assertEquals(4, relFields.size());
boolean found = false;
for (ResourceField relField : relFields) {
if (relField.getUnderlyingName().equals(TestEntity.ATTR_oneRelatedValue)) {
assertEquals(TestEntity.ATTR_oneRelatedValue, relField.getJsonName());
assertEquals(RelatedEntity.class, relField.getType());
assertEquals(RelatedEntity.class, relField.getGenericType());
found = true;
}
}
Assert.assertTrue(found);
}
use of io.crnk.core.engine.information.resource.ResourceInformation 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.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultQuerySpecDeserializerTestBase method testHyphenIsAllowedInResourceName.
@Test
public void testHyphenIsAllowedInResourceName() {
QuerySpec expectedSpec = new QuerySpec(Task.class);
expectedSpec.addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
Map<String, Set<String>> params = new HashMap<>();
add(params, "sort[task-with-lookup]", "id");
ResourceInformation taskWithLookUpInformation = resourceRegistry.getEntryForClass(TaskWithLookup.class).getResourceInformation();
QuerySpec actualSpec = deserializer.deserialize(taskWithLookUpInformation, params);
Assert.assertEquals(expectedSpec, actualSpec);
}
use of io.crnk.core.engine.information.resource.ResourceInformation 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.ResourceInformation in project crnk-framework by crnk-project.
the class ModuleRegistryTest method testInformationBuilder.
@Test
public void testInformationBuilder() throws Exception {
ResourceInformationProvider informationProvider = moduleRegistry.getResourceInformationBuilder();
Assert.assertTrue(informationProvider.accept(ComplexPojo.class));
Assert.assertTrue(informationProvider.accept(Document.class));
Assert.assertTrue(informationProvider.accept(FancyProject.class));
Assert.assertTrue(informationProvider.accept(Project.class));
Assert.assertTrue(informationProvider.accept(Task.class));
Assert.assertTrue(informationProvider.accept(Thing.class));
Assert.assertTrue(informationProvider.accept(User.class));
Assert.assertTrue(informationProvider.accept(TestResource.class));
Assert.assertFalse(informationProvider.accept(TestRepository.class));
Assert.assertFalse(informationProvider.accept(DocumentRepository.class));
Assert.assertFalse(informationProvider.accept(PojoRepository.class));
Assert.assertFalse(informationProvider.accept(ProjectRepository.class));
Assert.assertFalse(informationProvider.accept(ResourceWithoutRepositoryToProjectRepository.class));
Assert.assertFalse(informationProvider.accept(TaskToProjectRepository.class));
Assert.assertFalse(informationProvider.accept(TaskWithLookupRepository.class));
Assert.assertFalse(informationProvider.accept(UserRepository.class));
Assert.assertFalse(informationProvider.accept(UserToProjectRepository.class));
Assert.assertFalse(informationProvider.accept(Object.class));
Assert.assertFalse(informationProvider.accept(String.class));
try {
informationProvider.build(Object.class);
Assert.fail();
} catch (UnsupportedOperationException e) {
// ok
}
ResourceInformation userInfo = informationProvider.build(User.class);
Assert.assertEquals("id", userInfo.getIdField().getUnderlyingName());
ResourceInformation testInfo = informationProvider.build(TestResource.class);
Assert.assertEquals("id", testInfo.getIdField().getUnderlyingName());
// setup by TestResourceInformationProvider
Assert.assertEquals("testId", testInfo.getIdField().getJsonName());
}
Aggregations