use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest 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());
JsonMetaInformation meta = list.getMeta(JsonMetaInformation.class);
JsonLinksInformation links = list.getLinks(JsonLinksInformation.class);
Assert.assertNotNull(meta);
Assert.assertNotNull(links);
String baseUri = getBaseUri().toString();
Assert.assertEquals(baseUri + "test?page[limit]=2", links.asJsonNode().get("first").asText());
Assert.assertEquals(baseUri + "test?page[limit]=2&page[offset]=4", links.asJsonNode().get("last").asText());
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());
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testSaveAndFind.
@Test
public void testSaveAndFind() {
TestEntity task = new TestEntity();
task.setId(1L);
task.setStringValue("test");
testRepo.create(task);
// check retrievable with findAll
List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
Assert.assertEquals(1, list.size());
TestEntity savedTask = list.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
// check retrievable with findAll(ids)
list = testRepo.findAll(Arrays.asList(1L), new QuerySpec(TestEntity.class));
Assert.assertEquals(1, list.size());
savedTask = list.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
// check retrievable with findOne
savedTask = testRepo.findOne(1L, new QuerySpec(TestEntity.class));
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getStringValue(), savedTask.getStringValue());
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testLazyManyRelation.
@Test
public void testLazyManyRelation() throws InstantiationException, IllegalAccessException {
addTestWithManyRelations();
QuerySpec querySpec = new QuerySpec(TestEntity.class);
List<TestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
TestEntity testEntity = list.get(0);
List<RelatedEntity> manyRelatedValues = testEntity.getManyRelatedValues();
Assert.assertNotNull(manyRelatedValues);
ObjectProxy proxy = (ObjectProxy) manyRelatedValues;
Assert.assertFalse(proxy.isLoaded());
Assert.assertEquals(3, manyRelatedValues.size());
for (RelatedEntity relatedEntity : manyRelatedValues) {
Assert.assertNotNull(relatedEntity.getStringValue());
}
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testDelete.
@Test
public void testDelete() {
TestEntity test = new TestEntity();
test.setId(1L);
test.setStringValue("test");
testRepo.create(test);
testRepo.delete(1L);
List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
Assert.assertEquals(0, list.size());
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testIncludeEmptyRelations.
@Test
public void testIncludeEmptyRelations() throws InstantiationException, IllegalAccessException {
addTest();
QuerySpec querySpec = new QuerySpec(TestEntity.class);
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_oneRelatedValue));
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_manyRelatedValues));
List<TestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
for (TestEntity test : list) {
Assert.assertNull(test.getOneRelatedValue());
Assert.assertEquals(0, test.getManyRelatedValues().size());
}
}
Aggregations