Search in sources :

Example 1 with RelationIdTestResource

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());
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Serializable(java.io.Serializable) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec) RelationIdTestResource(io.crnk.test.mock.models.RelationIdTestResource) Test(org.junit.Test)

Aggregations

ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 RelationIdTestResource (io.crnk.test.mock.models.RelationIdTestResource)1 Schedule (io.crnk.test.mock.models.Schedule)1 Serializable (java.io.Serializable)1 Test (org.junit.Test)1