use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class ControllerMethodInvokerTest method create.
private ControllerMethodInvoker create(String methodName, final Object... toBind) {
Method method = null;
for (Method m : MockController.class.getMethods()) {
if (m.getName().equals(methodName)) {
method = m;
break;
}
}
return ControllerMethodInvoker.build(method, method, Guice.createInjector(new AbstractModule() {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void configure() {
Multibinder<ParamParser> parsersBinder = Multibinder.newSetBinder(binder(), ParamParser.class);
bind(NinjaProperties.class).toInstance(ninjaProperties);
for (Object o : toBind) {
if (o instanceof Class && ParamParser.class.isAssignableFrom((Class) o)) {
parsersBinder.addBinding().to((Class<? extends ParamParser>) o);
} else {
bind((Class<Object>) o.getClass()).toInstance(o);
}
}
}
}), ninjaProperties);
}
use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class ReverseRouterTest method before.
@Before
@SuppressWarnings("Convert2Lambda")
public void before() {
this.ninjaProperties = mock(NinjaProperties.class);
this.injector = mock(Injector.class);
this.testControllerProvider = mock(Provider.class);
this.ninjaBaseDirectoryResolver = new NinjaBaseDirectoryResolver(ninjaProperties);
when(testControllerProvider.get()).thenReturn(new TestController());
when(injector.getProvider(TestController.class)).thenReturn(testControllerProvider);
when(injector.getInstance(ParamParsers.class)).thenReturn(new ParamParsers(Collections.emptySet()));
Provider<RouteBuilderImpl> routeBuilderImplProvider = mock(Provider.class);
when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
reverseRouter = new ReverseRouter(ninjaProperties, router);
router.GET().route("/home").with(TestController::home);
router.GET().route("/user/{email}/{id: .*}").with(TestController::user);
router.GET().route("/u{userId: .*}/entries/{entryId: .*}").with(TestController::entry);
// second route to index should not break reverse routing matching the first
router.GET().route("/home/index").with(TestController::index);
router.compileRoutes();
}
use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class ControllerMethodInvokerWithDeprecatedValidationTest method create.
private ControllerMethodInvoker create(String methodName, final Object... toBind) {
Method method = null;
for (Method m : MockController.class.getMethods()) {
if (m.getName().equals(methodName)) {
method = m;
break;
}
}
return ControllerMethodInvoker.build(method, method, Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Multibinder<ParamParser> parsersBinder = Multibinder.newSetBinder(binder(), ParamParser.class);
bind(NinjaProperties.class).toInstance(ninjaProperties);
for (Object o : toBind) {
if (o instanceof Class && ParamParser.class.isAssignableFrom((Class) o)) {
parsersBinder.addBinding().to((Class<? extends ParamParser>) o);
} else {
bind((Class<Object>) o.getClass()).toInstance(o);
}
}
}
}), ninjaProperties);
}
use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class NinjaServletListenerTest method testCreatingInjectorWithoutContextAndOrPropertiesWorks.
@Test
public void testCreatingInjectorWithoutContextAndOrPropertiesWorks() {
NinjaServletListener ninjaServletListener = new NinjaServletListener();
ninjaServletListener.contextInitialized(servletContextEvent);
Injector injector = ninjaServletListener.getInjector();
NinjaProperties ninjaProperties = injector.getInstance(NinjaProperties.class);
// make sure we are using the context path from the serveltcontext here
assertThat(ninjaProperties.getContextPath(), equalTo(CONTEXT_PATH));
}
use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class NinjaServletListenerTest method testCreatingInjectorWithCustomNinjaPropertiesWorks.
@Test
public void testCreatingInjectorWithCustomNinjaPropertiesWorks() {
// setup stuff
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty("key!", "value!");
NinjaServletListener ninjaServletListener = new NinjaServletListener();
ninjaServletListener.setNinjaProperties(ninjaProperties);
// start the injector:
ninjaServletListener.contextInitialized(servletContextEvent);
// test stuff
Injector injector = ninjaServletListener.getInjector();
NinjaProperties ninjaPropertiesFromServer = injector.getInstance(NinjaProperties.class);
assertThat(ninjaPropertiesFromServer.get("key!"), equalTo("value!"));
// make sure we are using the context path from the serveltcontext here
assertThat(ninjaProperties.getContextPath(), equalTo(CONTEXT_PATH));
}
Aggregations