Search in sources :

Example 31 with Result

use of ninja.Result in project ninja by ninjaframework.

the class AbstractContextTest method finalizeInAbstractContextSavesFlashSessionCookies.

@Test
public void finalizeInAbstractContextSavesFlashSessionCookies() {
    AbstractContextImpl context = spy(abstractContext);
    Result result = Results.json();
    Cookie cookie = Cookie.builder("TEST", "value").build();
    result.addCookie(cookie);
    doNothing().when(context).addCookie(cookie);
    ResponseStreams streams = context.finalizeHeaders(result);
    // abstract finalizeHeaders does not return anything
    assertThat(streams, is(nullValue()));
    verify(flashCookie, times(1)).save(context);
    verify(sessionCookie, times(1)).save(context);
    verify(context, times(1)).addCookie(cookie);
}
Also used : Cookie(ninja.Cookie) Result(ninja.Result) Test(org.junit.Test)

Example 32 with Result

use of ninja.Result in project ninja by ninjaframework.

the class PrettyTimeController method indexWithLanguage.

public Result indexWithLanguage(@PathParam("language") String language) {
    Result result = Results.ok().html().template("/views/PrettyTimeController/index.ftl.html");
    // This gets an url like /prettyTime/en
    // language is then the "en" part of the url.
    // We take that part and set that language as the default language
    // of the framework for this user.
    lang.setLanguage(language, result);
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1);
    Date date = c.getTime();
    result.render("date", date);
    return result;
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) Result(ninja.Result)

Example 33 with Result

use of ninja.Result in project ninja by ninjaframework.

the class ApplicationController method flashSuccess.

@Timed
public Result flashSuccess(FlashScope flashScope, Context context) {
    Result result = Results.html();
    // sets a 18n flash message and adds a timestamp to make sure formatting works
    Optional<String> flashMessage = messages.get("flashSuccess", context, Optional.of(result), "PLACEHOLDER");
    if (flashMessage.isPresent()) {
        flashScope.success(flashMessage.get());
    }
    return result;
}
Also used : Result(ninja.Result) Timed(ninja.metrics.Timed)

Example 34 with Result

use of ninja.Result in project ninja by ninjaframework.

the class I18nController method indexWithLanguage.

public Result indexWithLanguage(@PathParam("language") String language) {
    Result result = Results.ok().html().template("/views/I18nController/index.ftl.html");
    // This gets an url like /i18n/en
    // language is then the "en" part of the url.
    // We take that part and set that language as the default language
    // of the framework for this user.
    lang.setLanguage(language, result);
    return result;
}
Also used : Result(ninja.Result)

Example 35 with Result

use of ninja.Result in project ninja by ninjaframework.

the class I18nController method index.

public Result index(Context context) {
    // Only render the page. It contains some language specific strings.
    // It will use the requested language (or a fallback language)
    // from Accept-Language header
    Result result = Results.html();
    // just in case we set the language => we remove it...
    lang.clearLanguage(result);
    return result;
}
Also used : Result(ninja.Result)

Aggregations

Result (ninja.Result)37 Test (org.junit.Test)26 TemplateModel (freemarker.template.TemplateModel)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Cookie (ninja.Cookie)6 SimpleScalar (freemarker.template.SimpleScalar)4 Context (ninja.Context)3 Timed (ninja.metrics.Timed)3 ResponseStreams (ninja.utils.ResponseStreams)3 BeansWrapper (freemarker.ext.beans.BeansWrapper)2 StringModel (freemarker.ext.beans.StringModel)2 Date (java.util.Date)2 ConstraintViolation (ninja.validation.ConstraintViolation)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1