use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testFindOneTargetWithNullResult.
@Test
public void testFindOneTargetWithNullResult() throws InstantiationException, IllegalAccessException {
TestEntity test = new TestEntity();
test.setId(2L);
test.setStringValue("test");
testRepo.create(test);
RelationshipRepositoryV2<TestEntity, Serializable, RelatedEntity, Serializable> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
RelatedEntity related = relRepo.findOneTarget(test.getId(), TestEntity.ATTR_oneRelatedValue, new QuerySpec(RelatedEntity.class));
Assert.assertNull(related);
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testSaveOneRelation.
@Test
public void testSaveOneRelation() {
TestEntity test = addTestWithOneRelation();
TestEntity savedTest = testRepo.findOne(2L, includeOneRelatedValueParams());
Assert.assertEquals(test.getId(), savedTest.getId());
Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
Assert.assertNotNull(savedTest.getOneRelatedValue());
Assert.assertEquals(1L, savedTest.getOneRelatedValue().getId().longValue());
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testIncludeManyRelations.
@Test
public void testIncludeManyRelations() throws InstantiationException, IllegalAccessException {
addTestWithManyRelations();
QuerySpec querySpec = new QuerySpec(TestEntity.class);
querySpec.includeRelation(Arrays.asList(TestEntity.ATTR_manyRelatedValues));
List<TestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
TestEntity testEntity = list.get(0);
List<RelatedEntity> manyRelatedValues = testEntity.getManyRelatedValues();
Assert.assertNotNull(manyRelatedValues);
Assert.assertEquals(3, manyRelatedValues.size());
}
use of io.crnk.jpa.model.TestEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest 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 QuerySpec(TestEntity.class));
Assert.assertEquals(test.getId(), savedTest.getId());
Assert.assertEquals(test.getStringValue(), savedTest.getStringValue());
Assert.assertNull(savedTest.getOneRelatedValue());
// TOOD 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 JpaQuerySpecEndToEndTest method testFindOneTarget.
@Test
public void testFindOneTarget() throws InstantiationException, IllegalAccessException {
TestEntity test = addTestWithOneRelation();
RelationshipRepositoryV2<TestEntity, Serializable, RelatedEntity, Serializable> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
RelatedEntity related = relRepo.findOneTarget(test.getId(), TestEntity.ATTR_oneRelatedValue, new QuerySpec(RelatedEntity.class));
Assert.assertNotNull(related);
}
Aggregations