Search in sources :

Example 6 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class CrnkFeatureTest method testSecurityRegistration.

private void testSecurityRegistration(boolean enabled) {
    CrnkFeature feature = new CrnkFeature();
    feature.setSecurityEnabled(enabled);
    feature.securityContext = Mockito.mock(SecurityContext.class);
    FeatureContext context = Mockito.mock(FeatureContext.class);
    Mockito.when(context.getConfiguration()).thenReturn(Mockito.mock(Configuration.class));
    feature.configure(context);
    CrnkBoot boot = feature.getBoot();
    if (enabled) {
        SecurityProvider securityProvider = boot.getModuleRegistry().getSecurityProvider();
        Assert.assertNotNull(securityProvider);
    } else {
        try {
            Assert.assertNull(boot.getModuleRegistry().getSecurityProvider());
            Assert.fail();
        } catch (IllegalStateException e) {
            Assert.assertTrue(e.getMessage().contains("exactly one security provide must be installed"));
        }
    }
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) Configuration(javax.ws.rs.core.Configuration) SecurityContext(javax.ws.rs.core.SecurityContext) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) FeatureContext(javax.ws.rs.core.FeatureContext)

Example 7 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class JaxrsModuleTest method checkSecurityProviderRegistered.

@Test
public void checkSecurityProviderRegistered() {
    SecurityContext securityContext = Mockito.mock(SecurityContext.class);
    JaxrsModule module = new JaxrsModule(securityContext);
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(module);
    boot.boot();
    SecurityProvider securityProvider = boot.getModuleRegistry().getSecurityProvider();
    Assert.assertNotNull(securityProvider);
    Mockito.when(securityContext.isUserInRole("admin")).thenReturn(true);
    Assert.assertTrue(securityProvider.isUserInRole("admin"));
    Assert.assertFalse(securityProvider.isUserInRole("other"));
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) SecurityContext(javax.ws.rs.core.SecurityContext) JaxrsModule(io.crnk.rs.internal.JaxrsModule) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) Test(org.junit.Test)

Example 8 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class CrnkFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    boot = new CrnkBoot();
    boot.setPropertiesProvider(new FilterPropertiesProvider(filterConfig));
    HttpRequestContextProvider provider = boot.getModuleRegistry().getHttpRequestContextProvider();
    boot.addModule(new ServletModule(provider));
    initCrnk(boot);
    boot.boot();
}
Also used : FilterPropertiesProvider(io.crnk.servlet.internal.FilterPropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ServletModule(io.crnk.servlet.internal.ServletModule) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider)

Example 9 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class HttpRequestProcessorImplTest method prepare.

@Before
public void prepare() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.addModule(new ActionTestModule());
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    moduleRegistry = boot.getModuleRegistry();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Before(org.junit.Before)

Example 10 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class JsonApiRequestProcessorTest method setup.

@Before
public void setup() {
    TaskRepository.clear();
    boot = new CrnkBoot();
    boot.addModule(new Module() {

        @Override
        public String getModuleName() {
            return "test";
        }

        @Override
        public void setupModule(ModuleContext context) {
            moduleContext = context;
        }
    });
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:8080"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.boot();
    Task task = new Task();
    task.setId(1L);
    task.setName("SomeTask");
    task.setLinksInformation(new TaskLinks());
    TaskRepository tasks = new TaskRepository();
    tasks.save(task);
    processor = new JsonApiRequestProcessor(moduleContext);
    requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
    HttpRequestContextProvider requestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
    requestContextProvider.onRequestStarted(requestContext);
}
Also used : HttpRequestContextBaseAdapter(io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter) Task(io.crnk.core.mock.models.Task) TaskRepository(io.crnk.core.mock.repository.TaskRepository) JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Module(io.crnk.core.module.Module) TaskLinks(io.crnk.core.mock.models.TaskLinks) Before(org.junit.Before)

Aggregations

CrnkBoot (io.crnk.core.boot.CrnkBoot)54 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)34 Before (org.junit.Before)34 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)28 Test (org.junit.Test)11 TestModule (io.crnk.test.mock.TestModule)9 SimpleModule (io.crnk.core.module.SimpleModule)7 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)6 MetaModule (io.crnk.meta.MetaModule)5 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 Task (io.crnk.core.mock.models.Task)4 TaskRepository (io.crnk.core.mock.repository.TaskRepository)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)4 JaxrsModule (io.crnk.rs.internal.JaxrsModule)4 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)3 HttpRequestContextProvider (io.crnk.core.engine.http.HttpRequestContextProvider)3