Search in sources :

Example 71 with ResourceField

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

the class JpaResourceInformationProviderTest method testManyToManyOppositeRelation.

@Test
public void testManyToManyOppositeRelation() {
    ResourceInformation info = builder.build(ManyToManyOppositeEntity.class);
    ResourceField field = info.findRelationshipFieldByName("tests");
    Assert.assertEquals(ResourceFieldType.RELATIONSHIP, field.getResourceFieldType());
    Assert.assertEquals("manyToManyTest", field.getOppositeResourceType());
    Assert.assertEquals(SerializeType.LAZY, field.getSerializeType());
    Assert.assertEquals("opposites", field.getOppositeName());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 72 with ResourceField

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

the class JpaResourceInformationProviderTest method testReadOnlyField.

@Test
public void testReadOnlyField() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    ResourceInformation info = builder.build(AnnotationTestEntity.class);
    ResourceField field = info.findAttributeFieldByName("readOnlyValue");
    Assert.assertFalse(field.getAccess().isPostable());
    Assert.assertFalse(field.getAccess().isPatchable());
    MetaDataObject meta = jpaMetaProvider.discoverMeta(AnnotationTestEntity.class).asDataObject();
    MetaAttribute attribute = meta.getAttribute("readOnlyValue");
    Assert.assertFalse(attribute.isInsertable());
    Assert.assertFalse(attribute.isUpdatable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 73 with ResourceField

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

the class JpaResourceInformationProviderTest method testOneToManyRelation.

@Test
public void testOneToManyRelation() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findRelationshipFieldByName("manyRelatedValues");
    Assert.assertEquals(ResourceFieldType.RELATIONSHIP, field.getResourceFieldType());
    Assert.assertEquals("related", field.getOppositeResourceType());
    Assert.assertEquals(SerializeType.LAZY, field.getSerializeType());
    Assert.assertEquals("testEntity", field.getOppositeName());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 74 with ResourceField

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

the class JpaResourceInformationProviderTest method testVersionAccess.

@Test
public void testVersionAccess() {
    ResourceInformation info = builder.build(VersionedEntity.class);
    ResourceField field = info.findAttributeFieldByName("version");
    // must not be immutable to support optimistic locking
    Assert.assertTrue(field.getAccess().isPostable());
    Assert.assertTrue(field.getAccess().isPatchable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 75 with ResourceField

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

the class JpaResourceInformationProviderTest method testAttributeAnnotations.

@Test
public void testAttributeAnnotations() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    ResourceInformation info = builder.build(AnnotationTestEntity.class);
    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(AnnotationTestEntity.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