Search in sources :

Example 41 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaQueryParamsEndToEndTest method testIncludeRelations.

@Test
public void testIncludeRelations() throws InstantiationException, IllegalAccessException {
    addTestWithOneRelation();
    List<TestEntity> list = findAll("include[test]", TestEntity.ATTR_oneRelatedValue);
    Assert.assertEquals(1, list.size());
    for (TestEntity test : list) {
        Assert.assertNotNull(test.getOneRelatedValue());
    }
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 42 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class JpaQueryParamsEndToEndTest method testEagerOneRelation.

@Test
public void testEagerOneRelation() {
    ResourceRepositoryStub<RelatedEntity, Long> relatedRepo = client.getQueryParamsRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(1L);
    related.setStringValue("project");
    relatedRepo.create(related);
    TestEntity test = new TestEntity();
    test.setId(2L);
    test.setStringValue("test");
    test.setEagerRelatedValue(related);
    testRepo.create(test);
    TestEntity savedTest = testRepo.findOne(2L, new QueryParams());
    Assert.assertEquals(test.getId(), savedTest.getId());
    Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
    Assert.assertNull(savedTest.getOneRelatedValue());
// TODO should @JsonApiIncludeByDefault trigger this?
// Assert.assertNotNull(savedTest.getEagerRelatedValue());
// Assert.assertEquals(1L, savedTest.getEagerRelatedValue().getId().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 43 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class HasNextPagingEndToEndTest method testRootPaging.

@Test
public void testRootPaging() {
    for (long i = 0; i < 5; i++) {
        TestEntity task = new TestEntity();
        task.setId(i);
        task.setStringValue("test");
        testRepo.create(task);
    }
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<TestEntity> list = testRepo.findAll(querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(2, list.get(0).getId().intValue());
    Assert.assertEquals(3, list.get(1).getId().intValue());
    JsonLinksInformation links = list.getLinks(JsonLinksInformation.class);
    String baseUri = getBaseUri().toString();
    Assert.assertEquals(baseUri + "test?page[limit]=2", links.asJsonNode().get("first").asText());
    // not available for hasNext
    Assert.assertNull(links.asJsonNode().get("last"));
    Assert.assertEquals(baseUri + "test?page[limit]=2", links.asJsonNode().get("prev").asText());
    Assert.assertEquals(baseUri + "test?page[limit]=2&page[offset]=4", links.asJsonNode().get("next").asText());
    JsonMetaInformation meta = list.getMeta(JsonMetaInformation.class);
    Assert.assertNull(meta);
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) JsonLinksInformation(io.crnk.client.response.JsonLinksInformation) JsonMetaInformation(io.crnk.client.response.JsonMetaInformation) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Example 44 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class MetaLookupTest method testObjectArrayMeta.

@Test
public void testObjectArrayMeta() {
    MetaArrayType meta = metaProvider.discoverMeta(TestEntity[].class);
    MetaType elementType = meta.getElementType();
    Assert.assertTrue(elementType instanceof MetaDataObject);
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaArrayType(io.crnk.meta.model.MetaArrayType) MetaType(io.crnk.meta.model.MetaType) Test(org.junit.Test)

Example 45 with TestEntity

use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.

the class TestDTOMapper method map.

@Override
public TestDTO map(Tuple tuple) {
    TestDTO dto = new TestDTO();
    TestEntity entity = tuple.get(0, TestEntity.class);
    dto.setId(entity.getId());
    dto.setStringValue(entity.getStringValue());
    dto.setComputedUpperStringValue(tuple.get("computedUpperStringValue", String.class));
    dto.setComputedNumberOfSmallerIds(tuple.get("computedNumberOfSmallerIds", Long.class));
    return dto;
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) TestDTO(io.crnk.jpa.model.dto.TestDTO)

Aggregations

TestEntity (io.crnk.jpa.model.TestEntity)61 Test (org.junit.Test)50 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)28 QuerySpec (io.crnk.core.queryspec.QuerySpec)25 RelatedEntity (io.crnk.jpa.model.RelatedEntity)24 AbstractJpaTest (io.crnk.jpa.query.AbstractJpaTest)16 OtherRelatedEntity (io.crnk.jpa.model.OtherRelatedEntity)12 QueryParams (io.crnk.legacy.queryParams.QueryParams)6 CollectionAttributesTestEntity (io.crnk.jpa.model.CollectionAttributesTestEntity)5 UuidTestEntity (io.crnk.jpa.model.UuidTestEntity)5 Serializable (java.io.Serializable)5 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)4 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)4 PagedMetaInformation (io.crnk.core.resource.meta.PagedMetaInformation)4 TestDTO (io.crnk.jpa.model.dto.TestDTO)2 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 JpaEntityRepository (io.crnk.jpa.JpaEntityRepository)1 JpaRepositoryFilterBase (io.crnk.jpa.JpaRepositoryFilterBase)1