use of io.crnk.jpa.model.OneToOneTestEntity 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