use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class HasNextPagingEndToEndTest method testRelationPaging.
@Test
public void testRelationPaging() {
TestEntity test = new TestEntity();
test.setId(1L);
test.setStringValue("test");
testRepo.create(test);
ResourceRepositoryStub<RelatedEntity, Long> relatedRepo = client.getQueryParamsRepository(RelatedEntity.class);
RelationshipRepositoryV2<TestEntity, Long, RelatedEntity, Long> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
for (long i = 0; i < 5; i++) {
RelatedEntity related1 = new RelatedEntity();
related1.setId(i);
related1.setStringValue("related" + i);
relatedRepo.create(related1);
relRepo.addRelations(test, Arrays.asList(i), TestEntity.ATTR_manyRelatedValues);
}
QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
querySpec.setOffset(2L);
querySpec.setLimit(2L);
ResourceList<RelatedEntity> list = relRepo.findManyTargets(test.getId(), TestEntity.ATTR_manyRelatedValues, 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.assertNull(meta);
Assert.assertNotNull(links);
String baseUri = getBaseUri().toString();
Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2", links.asJsonNode().get("first").asText());
Assert.assertNull(links.asJsonNode().get("last"));
Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2", links.asJsonNode().get("prev").asText());
Assert.assertEquals(baseUri + "test/1/relationships/manyRelatedValues?page[limit]=2&page[offset]=4", links.asJsonNode().get("next").asText());
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testIncludeNoRelations.
@Test
public void testIncludeNoRelations() throws InstantiationException, IllegalAccessException {
addTestWithOneRelation();
List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
Assert.assertEquals(1, list.size());
for (TestEntity test : list) {
// in the future we may get proxies here
Assert.assertNull(test.getOneRelatedValue());
}
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testUpdate.
@Test
public void testUpdate() throws InstantiationException, IllegalAccessException {
TestEntity test = addTest();
test.setLongValue(15);
testRepo.save(test);
List<TestEntity> list = testRepo.findAll(new QuerySpec(TestEntity.class));
Assert.assertEquals(1, list.size());
test = list.get(0);
Assert.assertEquals(15, test.getLongValue());
test.setLongValue(16);
testRepo.save(test);
list = testRepo.findAll(new QuerySpec(TestEntity.class));
Assert.assertEquals(1, list.size());
test = list.get(0);
Assert.assertEquals(16, test.getLongValue());
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testIncludeOneRelations.
@Test
public void testIncludeOneRelations() throws InstantiationException, IllegalAccessException {
addTestWithOneRelation();
QuerySpec querySpec = new QuerySpec(TestEntity.class);
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_oneRelatedValue));
List<TestEntity> list = testRepo.findAll(querySpec);
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 JpaQuerySpecEndToEndTest method testMappedSuperTypeWithPkOnSubclass.
@Test
public void testMappedSuperTypeWithPkOnSubclass() throws InstantiationException, IllegalAccessException {
ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
RelatedEntity related = new RelatedEntity();
related.setId(23423L);
related.setStringValue("test");
relatedRepo.create(related);
TestEntity entity = new TestEntity();
entity.setId(345345L);
entity.setLongValue(12L);
entity.setSuperRelatedValue(related);
testRepo.create(entity);
QuerySpec querySpec = new QuerySpec(TestEntity.class);
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_superRelatedValue));
List<TestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
TestEntity testEntity = list.get(0);
RelatedEntity superRelatedValue = testEntity.getSuperRelatedValue();
Assert.assertNotNull(superRelatedValue);
}
Aggregations