use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class CrnkBootTest method boot.
@Test
public void boot() {
CrnkBoot boot = new CrnkBoot();
boot.setDefaultServiceUrlProvider(new ServiceUrlProvider() {
@Override
public String getUrl() {
return "http://127.0.0.1";
}
});
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.addModule(new SimpleModule("test"));
boot.boot();
RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
ResourceRegistry resourceRegistry = boot.getResourceRegistry();
RegistryEntry taskEntry = resourceRegistry.getEntry(Task.class);
Assert.assertNotEquals(0, taskEntry.getRelationshipEntries().size());
ResourceRepositoryAdapter<?, ?> repositoryAdapter = taskEntry.getResourceRepository(null);
Assert.assertNotNull(repositoryAdapter.getResourceRepository());
JsonApiResponse response = repositoryAdapter.findAll(new QueryParamsAdapter(taskEntry.getResourceInformation(), new QueryParams(), boot.getModuleRegistry()));
Assert.assertNotNull(response);
Assert.assertNotNull(requestDispatcher);
ServiceDiscovery serviceDiscovery = boot.getServiceDiscovery();
Assert.assertNotNull(serviceDiscovery);
Assert.assertNotNull(boot.getModuleRegistry());
Assert.assertNotNull(boot.getExceptionMapperRegistry());
List<Module> modules = boot.getModuleRegistry().getModules();
Assert.assertEquals(4, modules.size());
boot.setDefaultPageLimit(20L);
boot.setMaxPageLimit(100L);
Assert.assertEquals(1, boot.getPagingBehaviors().size());
Assert.assertTrue(boot.getPagingBehaviors().get(0) instanceof OffsetLimitPagingBehavior);
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class FilterTest method prepare.
@Before
public void prepare() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
// GIVEN
filter = mock(TestFilter.class);
SimpleModule filterModule = new SimpleModule("filter");
filterModule.addFilter(filter);
boot.addModule(filterModule);
boot.boot();
resourceRegistry = boot.getResourceRegistry();
moduleRegistry = boot.getModuleRegistry();
pathBuilder = new PathBuilder(resourceRegistry);
ControllerRegistry controllerRegistry = new ControllerRegistry(null);
collectionGet = mock(CollectionGet.class);
controllerRegistry.addController(collectionGet);
QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
dispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class RepositoryFilterTest method prepare.
@Before
public void prepare() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
SimpleModule filterModule = new SimpleModule("filter");
filterModule.addRepositoryFilter(filter);
boot.addModule(filterModule);
boot.boot();
resourceRegistry = boot.getResourceRegistry();
querySpec = new QuerySpec(User.class);
querySpec.setPagingSpec(new OffsetLimitPagingSpec());
queryAdapter = new QuerySpecAdapter(querySpec, resourceRegistry);
scheduleInfo = resourceRegistry.getEntry(Schedule.class).getResourceInformation();
RegistryEntry userEntry = resourceRegistry.getEntry(User.class);
resourceAdapter = userEntry.getResourceRepository(null);
projectRelationAdapter = userEntry.getRelationshipRepository("assignedProjects", null);
taskRelationAdapter = userEntry.getRelationshipRepository("assignedTasks", null);
userInfo = userEntry.getResourceInformation();
UserRepository resourceRepository = (UserRepository) resourceAdapter.getResourceRepository();
user1 = new User();
user1.setId(1L);
resourceRepository.save(user1);
user2 = new User();
user2.setId(2L);
resourceRepository.save(user2);
UserToProjectRepository userProjectRepository = (UserToProjectRepository) ((AnnotatedRelationshipRepositoryAdapter<?, ?, ?, ?>) projectRelationAdapter.getRelationshipRepository()).getImplementationObject();
userProjectRepository.setRelation(user1, 11L, "assignedProjects");
UserToTaskRepository userTaskRepository = new UserToTaskRepository();
userTaskRepository.addRelations(user1, Arrays.asList(21L), "assignedTasks");
userTaskRepository.addRelations(user2, Arrays.asList(22L), "assignedTasks");
assignedTasksField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedTasks");
assignedProjectsField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedProjects");
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class JpaExceptionMapperTests method setup.
@Before
public void setup() {
boot = new CrnkBoot();
boot.addModule(JpaModule.newClientModule());
boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.jpa.mock.model", new SampleJsonServiceLocator()));
boot.boot();
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery 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);
}
}
Aggregations