Search in sources :

Example 1 with OneToOneTestEntity

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());
}
Also used : Serializable(java.io.Serializable) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OneToOneTestEntity(io.crnk.jpa.model.OneToOneTestEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)1 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)1 OneToOneTestEntity (io.crnk.jpa.model.OneToOneTestEntity)1 RelatedEntity (io.crnk.jpa.model.RelatedEntity)1 Serializable (java.io.Serializable)1 Test (org.junit.Test)1