use of io.crnk.test.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class RelationIdClientTest method checkResourceIdentifierField.
@Test
public void checkResourceIdentifierField() {
Schedule schedule = new Schedule();
schedule.setId(13L);
schedule.setName("mySchedule");
Schedule savedSchedule = scheduleRepo.create(schedule);
RelationIdTestResource resource = new RelationIdTestResource();
resource.setId(14L);
resource.setName("test");
resource.setTestResourceIdRefId(new ResourceIdentifier("13", "schedules"));
ResourceRepositoryV2<RelationIdTestResource, Serializable> repository = client.getRepositoryForType(RelationIdTestResource.class);
RelationIdTestResource createdResource = repository.create(resource);
Assert.assertEquals(resource.getTestResourceIdRefId(), createdResource.getTestResourceIdRefId());
RelationIdTestResource serverResource = RelationIdTestRepository.resources.get(14L);
Assert.assertEquals(resource.getTestResourceIdRefId(), serverResource.getTestResourceIdRefId());
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
RelationIdTestResource getResource = repository.findOne(14L, querySpec);
Assert.assertNull(getResource.getTestResourceIdRefId());
Assert.assertNull(createdResource.getTestResourceIdRef());
querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testResourceIdRef"));
getResource = repository.findOne(14L, querySpec);
Assert.assertEquals(resource.getTestResourceIdRefId(), getResource.getTestResourceIdRefId());
Assert.assertNotNull(getResource.getTestResourceIdRef());
}
Aggregations