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());
}
}
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());
}
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);
}
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);
}
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;
}
Aggregations