Search in sources :

Example 36 with ResourceField

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

the class JpaResourceInformationProviderTest method testLongAttributeAccess.

@Test
public void testLongAttributeAccess() {
    ResourceInformation info = builder.build(VersionedEntity.class);
    ResourceField field = info.findAttributeFieldByName("longValue");
    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 37 with ResourceField

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

the class JpaResourceInformationProviderTest method testStringAttributeAccess.

@Test
public void testStringAttributeAccess() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findAttributeFieldByName("stringValue");
    Assert.assertTrue(field.getAccess().isPostable());
    Assert.assertTrue(field.getAccess().isPatchable());
    Assert.assertTrue(field.getAccess().isSortable());
    Assert.assertTrue(field.getAccess().isFilterable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 38 with ResourceField

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

the class JpaResourceInformationProviderTest method testPrimitiveTypesProperlyRecognized.

@Test
public void testPrimitiveTypesProperlyRecognized() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findAttributeFieldByName("longValue");
    Assert.assertNotNull(field);
    Assert.assertEquals(long.class, field.getType());
    Assert.assertEquals(long.class, field.getGenericType());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 39 with ResourceField

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

the class JpaResourceInformationProviderTest method testManyToOneRelation.

@Test
public void testManyToOneRelation() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findRelationshipFieldByName("oneRelatedValue");
    Assert.assertEquals(ResourceFieldType.RELATIONSHIP, field.getResourceFieldType());
    Assert.assertEquals("related", field.getOppositeResourceType());
    Assert.assertEquals(SerializeType.LAZY, field.getSerializeType());
    Assert.assertNull(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 40 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField 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);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ArrayList(java.util.ArrayList) 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