use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineFreemarkerI18nMethodTest method testThatKeyWithPlaceholderWorks.
@Test
public void testThatKeyWithPlaceholderWorks() throws Exception {
Optional<Result> resultOptional = Optional.of(result);
List args = new ArrayList();
args.add(new SimpleScalar("my.message.key"));
args.add(new SimpleScalar("1000"));
Mockito.when(messages.get(Matchers.eq("my.message.key"), Matchers.eq(context), Matchers.eq(resultOptional), Matchers.any(Object.class))).thenReturn(Optional.of("This simulates the translated message number 1000!"));
TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("This simulates the translated message number 1000!"));
Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineFreemarkerI18nMethodTest method testThatSingleKeyWithMissingValueReturnsDefaultKey.
@Test
public void testThatSingleKeyWithMissingValueReturnsDefaultKey() throws Exception {
Optional<Result> resultOptional = Optional.of(result);
Mockito.when(messages.get("my.message.key", context, resultOptional)).thenReturn(Optional.<String>empty());
List args = new ArrayList();
args.add(new SimpleScalar("my.message.key"));
TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("my.message.key"));
// There must have been logged something because we did not find
// the value for the key...
Mockito.verify(mockAppender).doAppend(Matchers.anyObject());
}
use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineFreemarkerI18nMethodTest method testThatConstraintViolationWorksWithDefault.
@Test
public void testThatConstraintViolationWorksWithDefault() throws Exception {
Optional<Result> resultOptional = Optional.of(result);
Mockito.when(messages.get(IsInteger.KEY, context, resultOptional)).thenReturn(Optional.empty());
ConstraintViolation violation = new ConstraintViolation(IsInteger.KEY, "theField", IsInteger.MESSAGE);
List args = new ArrayList();
args.add(new StringModel(violation, new BeansWrapper()));
TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("theField must be an integer"));
Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineFreemarkerI18nMethodTest method testThatConstraintViolationWorks.
@Test
public void testThatConstraintViolationWorks() throws Exception {
Optional<Result> resultOptional = Optional.of(result);
Mockito.when(messages.get(IsInteger.KEY, context, resultOptional)).thenReturn(Optional.of("This simulates the translated message!"));
ConstraintViolation violation = new ConstraintViolation(IsInteger.KEY, "theField", IsInteger.MESSAGE);
List args = new ArrayList();
args.add(new StringModel(violation, new BeansWrapper()));
TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("This simulates the translated message!"));
Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
use of ninja.Result in project ninja by ninjaframework.
the class LangImplTest method testClearLanguage.
@Test
public void testClearLanguage() {
Cookie cookie = Cookie.builder("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX, "de").build();
when(ninjaProperties.getOrDie(NinjaConstant.applicationCookiePrefix)).thenReturn("NINJA_TEST");
Lang lang = new LangImpl(ninjaProperties);
Result result = Results.ok();
lang.clearLanguage(result);
Cookie returnCookie = result.getCookie(cookie.getName());
assertEquals("", returnCookie.getValue());
assertEquals(0, returnCookie.getMaxAge());
}
Aggregations