Search in sources :

Example 6 with ReflectionsServiceDiscovery

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);
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QueryParams(io.crnk.legacy.queryParams.QueryParams) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) SimpleModule(io.crnk.core.module.SimpleModule) Module(io.crnk.core.module.Module) SimpleModule(io.crnk.core.module.SimpleModule) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Test(org.junit.Test)

Example 7 with ReflectionsServiceDiscovery

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);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Before(org.junit.Before)

Example 8 with ReflectionsServiceDiscovery

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");
}
Also used : UserToProjectRepository(io.crnk.core.mock.repository.UserToProjectRepository) CrnkBoot(io.crnk.core.boot.CrnkBoot) User(io.crnk.core.mock.models.User) UserRepository(io.crnk.core.mock.repository.UserRepository) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) UserToTaskRepository(io.crnk.core.mock.repository.UserToTaskRepository) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) QuerySpec(io.crnk.core.queryspec.QuerySpec) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 9 with ReflectionsServiceDiscovery

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();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Before(org.junit.Before)

Example 10 with ReflectionsServiceDiscovery

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);
    }
}
Also used : Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ScheduleRepositoryImpl(io.crnk.core.mock.repository.ScheduleRepositoryImpl) Project(io.crnk.core.mock.models.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ImplicitOwnerBasedRelationshipRepository(io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository) Schedule(io.crnk.core.mock.models.Schedule) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Before(org.junit.Before)

Aggregations

ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)30 CrnkBoot (io.crnk.core.boot.CrnkBoot)28 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)25 Before (org.junit.Before)22 Test (org.junit.Test)7 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)5 Task (io.crnk.core.mock.models.Task)5 SimpleModule (io.crnk.core.module.SimpleModule)4 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)3 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)2 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)2 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)2 Project (io.crnk.core.mock.models.Project)2 Schedule (io.crnk.core.mock.models.Schedule)2 User (io.crnk.core.mock.models.User)2 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)2 ScheduleRepositoryImpl (io.crnk.core.mock.repository.ScheduleRepositoryImpl)2 TaskRepository (io.crnk.core.mock.repository.TaskRepository)2 Module (io.crnk.core.module.Module)2