Search in sources :

Example 6 with ResourceFieldAccessor

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

the class DefaultInformationBuilderTest method checkRelationIdFieldCreation.

@Test
public void checkRelationIdFieldCreation() {
    InformationBuilder.Resource resource = builder.createResource(Task.class, "tasks");
    resource.superResourceType("superTask");
    resource.resourceType("changedTasks");
    resource.resourceClass(Project.class);
    InformationBuilder.Field idField = resource.addField("id", ResourceFieldType.ID, String.class);
    idField.serializeType(SerializeType.EAGER);
    idField.access(new ResourceFieldAccess(true, true, true, false, false));
    ResourceFieldAccessor idAccessor = Mockito.mock(ResourceFieldAccessor.class);
    ResourceFieldAccessor accessor = Mockito.mock(ResourceFieldAccessor.class);
    InformationBuilder.Field projectField = resource.addField("project", ResourceFieldType.RELATIONSHIP, Project.class);
    projectField.idName("taskId");
    projectField.idAccessor(idAccessor);
    projectField.idType(Long.class);
    projectField.serializeType(SerializeType.EAGER);
    projectField.access(new ResourceFieldAccess(true, false, true, false, false));
    projectField.oppositeName("tasks");
    projectField.lookupIncludeBehavior(LookupIncludeBehavior.AUTOMATICALLY_ALWAYS);
    projectField.accessor(accessor);
    ResourceInformation info = resource.build();
    Assert.assertEquals("changedTasks", info.getResourceType());
    Assert.assertEquals(Project.class, info.getResourceClass());
    Assert.assertEquals("superTask", info.getSuperResourceType());
    ResourceField projectInfo = info.findFieldByName("project");
    Assert.assertEquals("project", projectInfo.getUnderlyingName());
    Assert.assertEquals("tasks", projectInfo.getOppositeName());
    Assert.assertEquals(LookupIncludeBehavior.AUTOMATICALLY_ALWAYS, projectInfo.getLookupIncludeAutomatically());
    Assert.assertEquals(Project.class, projectInfo.getType());
    Assert.assertSame(accessor, projectInfo.getAccessor());
    Assert.assertFalse(projectInfo.getAccess().isFilterable());
    Assert.assertFalse(projectInfo.getAccess().isSortable());
    Assert.assertFalse(projectInfo.getAccess().isPostable());
    Assert.assertTrue(projectInfo.getAccess().isPatchable());
    Assert.assertEquals(SerializeType.EAGER, projectInfo.getSerializeType());
    Assert.assertTrue(projectInfo.hasIdField());
    Assert.assertEquals("taskId", projectInfo.getIdName());
    Assert.assertEquals(Long.class, projectInfo.getIdType());
    Assert.assertSame(idAccessor, projectInfo.getIdAccessor());
    Assert.assertFalse(projectInfo.isCollection());
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldAccessor(io.crnk.core.engine.information.resource.ResourceFieldAccessor) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceFieldAccess(io.crnk.core.engine.information.resource.ResourceFieldAccess) Test(org.junit.Test)

Aggregations

ResourceFieldAccessor (io.crnk.core.engine.information.resource.ResourceFieldAccessor)6 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)5 ResourceFieldAccess (io.crnk.core.engine.information.resource.ResourceFieldAccess)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 Test (org.junit.Test)2 TypeToken (com.google.common.reflect.TypeToken)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 ResourceFieldType (io.crnk.core.engine.information.resource.ResourceFieldType)1 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)1 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)1 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)1 ResourceFieldImpl (io.crnk.core.engine.internal.information.resource.ResourceFieldImpl)1 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)1 TypeParser (io.crnk.core.engine.parser.TypeParser)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 SimpleModule (io.crnk.core.module.SimpleModule)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1