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"));
}
}
}
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"));
}
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();
}
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();
}
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);
}
Aggregations