Search in sources :

Example 66 with ResourceField

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));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Schedule(io.crnk.core.mock.models.Schedule) Test(org.junit.Test)

Example 67 with ResourceField

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());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.core.mock.models.Task) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceFieldImpl(io.crnk.core.engine.internal.information.resource.ResourceFieldImpl) TypeParser(io.crnk.core.engine.parser.TypeParser) Before(org.junit.Before)

Example 68 with ResourceField

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);
}
Also used : FieldOrderedComparator(io.crnk.core.engine.internal.utils.FieldOrderedComparator) ResourceField(io.crnk.core.engine.information.resource.ResourceField) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 69 with ResourceField

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);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) HashMap(java.util.HashMap) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) HashMap(java.util.HashMap) Map(java.util.Map) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 70 with ResourceField

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());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaDataObject(io.crnk.meta.model.MetaDataObject) 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