use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class MultiValuedRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestMultipleValueIds(Arrays.asList(3L, 4L));
} else {
entity.setTestMultipleValueIds(null);
}
if (setRelatedEntity) {
entity.setTestMultipleValues(Arrays.asList(schedule3, schedule4));
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testMultipleValues"));
Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
Resource resource = document.getSingleData().get();
Assert.assertEquals("2", resource.getId());
Assert.assertEquals("relationIdTest", resource.getType());
Assert.assertEquals("test", resource.getAttributes().get("name").asText());
Nullable<ResourceIdentifier> data = resource.getRelationships().get("testMultipleValues").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(2, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
Assert.assertEquals("4", document.getIncluded().get(1).getId());
if (setRelatedEntity) {
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
} else {
Assert.assertEquals(1, scheduleRepository.getNumFindAll());
}
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class ResourceIdBasedRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestResourceIdRefId(new ResourceIdentifier("3", "schedules"));
}
if (setRelatedEntity) {
entity.setTestResourceIdRef(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testResourceIdRef"));
Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
Resource resource = document.getSingleData().get();
Assert.assertEquals("2", resource.getId());
Assert.assertEquals("relationIdTest", resource.getType());
Assert.assertEquals("test", resource.getAttributes().get("name").asText());
Nullable<ResourceIdentifier> data = resource.getRelationships().get("testResourceIdRef").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(1, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
Assert.assertEquals(setRelatedEntity ? 0 : 1, scheduleRepository.getNumFindAll());
} else {
Assert.assertNull(data.get());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class SerializeOnlyIdRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestSerializeOnlyIdId(3L);
}
if (setRelatedEntity) {
entity.setTestSerializeOnlyId(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
Resource resource = document.getSingleData().get();
Assert.assertEquals("2", resource.getId());
Assert.assertEquals("relationIdTest", resource.getType());
Assert.assertEquals("test", resource.getAttributes().get("name").asText());
Nullable<ResourceIdentifier> data = resource.getRelationships().get("testSerializeOnlyId").getSingleData();
Assert.assertTrue(data.isPresent());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
Assert.assertEquals(0, document.getIncluded().size());
if (setRelatedEntity || setRelatedId) {
Assert.assertNotNull(data.get());
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class RawResourceFieldAccessorTest method relationship.
@Test
public void relationship() {
RawResourceFieldAccessor accessor = new RawResourceFieldAccessor("address", ResourceFieldType.RELATIONSHIP, ResourceIdentifier.class);
ResourceIdentifier value = (ResourceIdentifier) accessor.getValue(resource);
Assert.assertEquals("zurich", value.getId());
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class DependencyOrderStrategyTest method addOneDependency.
private void addOneDependency(Operation op1, Operation op2, String relationshipName) {
Resource resource1 = op1.getValue();
Resource resource2 = op2.getValue();
Relationship relationship = resource1.getRelationships().get(relationshipName);
if (relationship == null) {
relationship = new Relationship();
resource1.getRelationships().put(relationshipName, relationship);
}
ResourceIdentifier resourceId = new ResourceIdentifier(resource2.getId(), resource2.getType());
relationship.setData(Nullable.of((Object) resourceId));
}
Aggregations