use of io.crnk.jpa.model.RelatedEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method testMappedSuperTypeWithPkOnSuperType.
@Test
public void testMappedSuperTypeWithPkOnSuperType() throws InstantiationException, IllegalAccessException {
ResourceRepositoryV2<TestSubclassWithSuperclassPk, Serializable> repo = client.getQuerySpecRepository(TestSubclassWithSuperclassPk.class);
ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
RelatedEntity related = new RelatedEntity();
related.setId(23423L);
related.setStringValue("test");
relatedRepo.create(related);
TestSubclassWithSuperclassPk entity = new TestSubclassWithSuperclassPk();
entity.setId("test");
entity.setLongValue(12L);
entity.setSuperRelatedValue(related);
repo.create(entity);
QuerySpec querySpec = new QuerySpec(TestSubclassWithSuperclassPk.class);
querySpec.includeRelation(Arrays.asList(TestMappedSuperclassWithPk.ATTR_superRelatedValue));
List<TestSubclassWithSuperclassPk> list = repo.findAll(querySpec);
Assert.assertEquals(1, list.size());
TestSubclassWithSuperclassPk testEntity = list.get(0);
RelatedEntity superRelatedValue = testEntity.getSuperRelatedValue();
Assert.assertNotNull(superRelatedValue);
}
use of io.crnk.jpa.model.RelatedEntity 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.RelatedEntity 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.RelatedEntity 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);
}
use of io.crnk.jpa.model.RelatedEntity in project crnk-framework by crnk-project.
the class SaveRelationshipWithResourceEndToEndTest method testOneToOne.
@Test
public void testOneToOne() throws InstantiationException, IllegalAccessException {
RelatedEntity related = new RelatedEntity();
related.setId(12L);
ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getRepositoryForType(RelatedEntity.class);
relatedRepo.create(related);
OneToOneTestEntity test = new OneToOneTestEntity();
test.setId(11L);
test.setOneRelatedValue(related);
ResourceRepositoryV2<OneToOneTestEntity, Serializable> testRepo = client.getRepositoryForType(OneToOneTestEntity.class);
testRepo.create(test);
QuerySpec querySpec = new QuerySpec(OneToOneTestEntity.class);
querySpec.includeRelation(Arrays.asList("oneRelatedValue"));
ResourceList<OneToOneTestEntity> list = testRepo.findAll(querySpec);
Assert.assertEquals(1, list.size());
OneToOneTestEntity testCopy = list.get(0);
Assert.assertNotNull(testCopy.getOneRelatedValue());
Assert.assertEquals(12L, testCopy.getOneRelatedValue().getId().longValue());
}
Aggregations