use of io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository in project crnk-framework by crnk-project.
the class ImplicitOwnerBasedRelationshipRepositoryTest 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 = new ImplicitOwnerBasedRelationshipRepository(RelationIdTestResource.class, Schedule.class);
relRepository.setResourceRegistry(resourceRegistry);
taskProjectRepository = new ImplicitOwnerBasedRelationshipRepository(Task.class, Project.class);
taskProjectRepository.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.repository.implicit.ImplicitOwnerBasedRelationshipRepository in project crnk-framework by crnk-project.
the class ImplicitOwnerBasedRelationshipRepositoryTest method testSourceOnlyClassConstructor.
@Test
public void testSourceOnlyClassConstructor() {
RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
ResourceField otherField = entry.getResourceInformation().findFieldByUnderlyingName("testNested");
ResourceField relField = entry.getResourceInformation().findRelationshipFieldByName("testSerializeEager");
ImplicitOwnerBasedRelationshipRepository repo = new ImplicitOwnerBasedRelationshipRepository(RelationIdTestResource.class);
repo.setResourceRegistry(resourceRegistry);
Assert.assertTrue(repo.getMatcher().matches(otherField));
Assert.assertTrue(repo.getMatcher().matches(relField));
relRepository.setRelation(resource, 3L, "testSerializeEager");
Assert.assertEquals(3L, resource.getTestSerializeEagerId().longValue());
Assert.assertNull(resource.getTestSerializeEager());
Assert.assertSame(schedule3, relRepository.findOneTarget(resource.getId(), "testSerializeEager", new QuerySpec(Schedule.class)));
}
use of io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository in project crnk-framework by crnk-project.
the class ImplicitOwnerBasedRelationshipRepositoryTest method testSourceTargetResourceTypeConstructor.
@Test
public void testSourceTargetResourceTypeConstructor() {
RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
ResourceField otherField = entry.getResourceInformation().findFieldByUnderlyingName("testNested");
ResourceField relField = entry.getResourceInformation().findRelationshipFieldByName("testSerializeEager");
ImplicitOwnerBasedRelationshipRepository repo = new ImplicitOwnerBasedRelationshipRepository("relationIdTest", "schedules");
repo.setResourceRegistry(resourceRegistry);
Assert.assertFalse(repo.getMatcher().matches(otherField));
Assert.assertTrue(repo.getMatcher().matches(relField));
relRepository.setRelation(resource, 3L, "testSerializeEager");
Assert.assertEquals(3L, resource.getTestSerializeEagerId().longValue());
Assert.assertNull(resource.getTestSerializeEager());
Assert.assertSame(schedule3, relRepository.findOneTarget(resource.getId(), "testSerializeEager", new QuerySpec(Schedule.class)));
}
Aggregations