use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class OppositeFowardingRelationshipRepositoryTest method checkFindOneTargetFromSingleValue.
@Test
public void checkFindOneTargetFromSingleValue() {
RelationIdTestResource parent = new RelationIdTestResource();
parent.setId(2L);
parent.setName("parent");
RelationIdTestResource child = new RelationIdTestResource();
child.setId(3L);
child.setName("child");
parent.setTestNested(child);
testRepository.create(parent);
testRepository.create(child);
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
Object target = relRepository.findOneTarget(3L, "testNestedOpposite", querySpec);
Assert.assertNotNull(target);
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class OwnerFowardingRelationshipRepositoryTest method setup.
@Before
public void setup() {
MockRepositoryUtil.clear();
CrnkBoot boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
boot.boot();
resourceRegistry = boot.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
relRepository = (ForwardingRelationshipRepository) entry.getRelationshipRepository("testSerializeEager", null).getRelationshipRepository();
RelationshipMatcher taskProjectMatcher = new RelationshipMatcher().rule().source(Task.class).target(Project.class).add();
taskProjectRepository = new ForwardingRelationshipRepository(Task.class, taskProjectMatcher, ForwardingDirection.OWNER, ForwardingDirection.OWNER);
taskProjectRepository.setResourceRegistry(resourceRegistry);
projectTaskRepository = new ForwardingRelationshipRepository(Project.class, taskProjectMatcher, ForwardingDirection.OWNER, ForwardingDirection.OWNER);
projectTaskRepository.setResourceRegistry(resourceRegistry);
testRepository = (RelationIdTestRepository) entry.getResourceRepository().getResourceRepository();
testRepository.setResourceRegistry(resourceRegistry);
resource = new RelationIdTestResource();
resource.setId(2L);
resource.setName("relationId");
testRepository.create(resource);
scheduleRepository = new ScheduleRepositoryImpl();
schedule3 = new Schedule();
schedule3.setId(3L);
schedule3.setName("schedule");
scheduleRepository.create(schedule3);
for (int i = 0; i < 10; i++) {
schedule = new Schedule();
schedule.setId(4L + i);
schedule.setName("schedule");
scheduleRepository.create(schedule);
projectRepository = new ProjectRepository();
project = new Project();
project.setId(42L + i);
project.setName("project");
projectRepository.save(project);
taskRepository = new TaskRepository();
task = new Task();
task.setId(13L + i);
task.setName("task");
taskRepository.save(task);
}
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class ResourceIdControllerTest method checkPost.
private Resource checkPost() throws IOException {
// GIVEN
Resource resource = createResource();
resource.getRelationships().put("testLookupAlways", new Relationship(schedule3Id));
Document newDocument = createDocument(resource);
JsonPath postPath = pathBuilder.build("/relationIdTest");
// WHEN POST
ResourcePost sut = new ResourcePost(resourceRegistry, new NullPropertiesProvider(), typeParser, objectMapper, documentMapper, modificationFilters);
Response taskResponse = sut.handle(postPath, emptyTaskQuery, null, newDocument);
// THEN POST
assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.CREATED_201);
Resource createdResource = taskResponse.getDocument().getSingleData().get();
Assert.assertEquals(resource.getType(), createdResource.getType());
Assert.assertEquals(resource.getId(), createdResource.getId());
Assert.assertEquals(resource.getAttributes().get("name"), createdResource.getAttributes().get("name"));
Relationship relationship = createdResource.getRelationships().get("testLookupAlways");
Assert.assertTrue(relationship.getData().isPresent());
Assert.assertEquals(schedule3Id, relationship.getData().get());
// validate relationship not accessed, only id set => performance
RelationIdTestResource entity = repository.findOne(1L, new QuerySpec(RelationIdTestResource.class));
Assert.assertEquals(schedule3.getId(), entity.getTestLookupAlwaysId());
Assert.assertNull(entity.getTestLookupAlways());
return createdResource;
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class ResourceIdControllerTest method checkPatchRelationship.
private void checkPatchRelationship(Resource resource, ResourceIdentifier scheduleId) {
JsonPath path = pathBuilder.build("/relationIdTest/" + resource.getId() + "/relationships/testLookupAlways");
Document newDocument = createDocument(scheduleId);
// WHEN PATCH
RelationshipsResourcePatch sut = new RelationshipsResourcePatch(resourceRegistry, typeParser, modificationFilters);
Response taskResponse = sut.handle(path, emptyTaskQuery, null, newDocument);
// THEN PATCH
assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.NO_CONTENT_204);
// validate relationship not accessed, only id set => performance
RelationIdTestResource entity = repository.findOne(1L, new QuerySpec(RelationIdTestResource.class));
Assert.assertEquals(scheduleId != null ? Long.parseLong(scheduleId.getId()) : null, entity.getTestLookupAlwaysId());
Assert.assertNull(entity.getTestLookupAlways());
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class NestedRelationIdLookupTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
super.setup();
scheduleRepository = new ScheduleRepositoryImpl();
schedule = new Schedule();
schedule.setId(3L);
schedule.setName("test");
scheduleRepository.save(schedule);
testRepository = new RelationIdTestRepository();
child = new RelationIdTestResource();
child.setId(1L);
child.setName("child");
testRepository.save(child);
child.setTestSerializeEager(schedule);
}
Aggregations