use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class JsonApiRelationIdInformationProviderTest method shouldAutoDetectWithDefaultName.
@Test
public void shouldAutoDetectWithDefaultName() {
ResourceInformation resourceInformation = resourceInformationProvider.build(Schedule.class);
ResourceField field = resourceInformation.findFieldByName("project");
Assert.assertNotNull(field);
Assert.assertNull(resourceInformation.findFieldByName("projectId"));
Assert.assertTrue(field.hasIdField());
Schedule schedule = new Schedule();
Assert.assertNull(field.getIdAccessor().getValue(schedule));
field.getIdAccessor().setValue(schedule, 13L);
Assert.assertEquals(13L, schedule.getProjectId().longValue());
Assert.assertEquals(13L, field.getIdAccessor().getValue(schedule));
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class ResourceInformationTest method setup.
@Before
public void setup() throws NoSuchFieldException {
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");
TypeParser typeParser = new TypeParser();
sut = new ResourceInformation(typeParser, Task.class, "tasks", null, Arrays.asList(idField, valueField), new OffsetLimitPagingBehavior());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class FieldOrderedComparatorTest method onTwoFieldsShouldSortCorrectly.
@Test
public void onTwoFieldsShouldSortCorrectly() throws Exception {
// GIVEN
Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] { "b", "a" }, false));
// WHEN
fields.add(fieldA);
fields.add(fieldB);
// THEN
assertThat(fields).containsSequence(fieldB, fieldA);
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.
@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
// GIVEN
ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
Map relRepos = new HashMap<>();
relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
// THEN
expectedException.expect(ResourceFieldNotFoundException.class);
// WHEN
sut.getRelationshipRepository("users", null);
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class JpaResourceInformationProviderTest method testMappedSuperclass.
@Test
public void testMappedSuperclass() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
ResourceInformation info = builder.build(AnnotationMappedSuperclassEntity.class);
Assert.assertNull(info.getResourceType());
ResourceField lobField = info.findAttributeFieldByName("lobValue");
ResourceField fieldAnnotatedField = info.findAttributeFieldByName("fieldAnnotatedValue");
ResourceField columnAnnotatedField = info.findAttributeFieldByName("columnAnnotatedValue");
Assert.assertFalse(lobField.getAccess().isSortable());
Assert.assertFalse(lobField.getAccess().isFilterable());
Assert.assertTrue(lobField.getAccess().isPostable());
Assert.assertTrue(lobField.getAccess().isPatchable());
Assert.assertFalse(fieldAnnotatedField.getAccess().isSortable());
Assert.assertFalse(fieldAnnotatedField.getAccess().isFilterable());
Assert.assertTrue(fieldAnnotatedField.getAccess().isPostable());
Assert.assertFalse(fieldAnnotatedField.getAccess().isPatchable());
Assert.assertTrue(columnAnnotatedField.getAccess().isSortable());
Assert.assertTrue(columnAnnotatedField.getAccess().isFilterable());
Assert.assertFalse(columnAnnotatedField.getAccess().isPostable());
Assert.assertTrue(columnAnnotatedField.getAccess().isPatchable());
MetaDataObject meta = jpaMetaProvider.discoverMeta(AnnotationMappedSuperclassEntity.class).asDataObject();
Assert.assertTrue(meta.getAttribute("lobValue").isLob());
Assert.assertFalse(meta.getAttribute("fieldAnnotatedValue").isLob());
}
Aggregations