Search in sources :

Example 1 with FlashScope

use of ninja.session.FlashScope in project ninja by ninjaframework.

the class TemplateEngineFreemarkerTest method before.

@Before
public void before() throws Exception {
    //Setup that allows to to execute invoke(...) in a very minimal version.
    when(ninjaProperties.getWithDefault(FREEMARKER_CONFIGURATION_FILE_SUFFIX, ".ftl.html")).thenReturn(".ftl.html");
    templateEngineFreemarker = new TemplateEngineFreemarker(messages, lang, logger, templateEngineHelper, templateEngineManager, templateEngineFreemarkerReverseRouteMethod, templateEngineFreemarkerAssetsAtMethod, templateEngineFreemarkerWebJarsAtMethod, ninjaProperties);
    when(lang.getLanguage(any(Context.class), any(Optional.class))).thenReturn(Optional.<String>empty());
    Session session = Mockito.mock(Session.class);
    when(session.isEmpty()).thenReturn(true);
    when(context.getSession()).thenReturn(session);
    when(context.getRoute()).thenReturn(route);
    when(lang.getLocaleFromStringOrDefault(any(Optional.class))).thenReturn(Locale.ENGLISH);
    FlashScope flashScope = Mockito.mock(FlashScope.class);
    Map<String, String> flashScopeData = new HashMap<>();
    when(flashScope.getCurrentFlashCookieData()).thenReturn(flashScopeData);
    when(context.getFlashScope()).thenReturn(flashScope);
    when(templateEngineHelper.getTemplateForResult(any(Route.class), any(Result.class), Mockito.anyString())).thenReturn("views/template.ftl.html");
    writer = new StringWriter();
    ResponseStreams responseStreams = mock(ResponseStreams.class);
    when(context.finalizeHeaders(any(Result.class))).thenReturn(responseStreams);
    when(responseStreams.getWriter()).thenReturn(writer);
}
Also used : Context(ninja.Context) Optional(java.util.Optional) StringWriter(java.io.StringWriter) ResponseStreams(ninja.utils.ResponseStreams) HashMap(java.util.HashMap) FlashScope(ninja.session.FlashScope) Route(ninja.Route) Session(ninja.session.Session) Result(ninja.Result) Before(org.junit.Before)

Aggregations

StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Context (ninja.Context)1 Result (ninja.Result)1 Route (ninja.Route)1 FlashScope (ninja.session.FlashScope)1 Session (ninja.session.Session)1 ResponseStreams (ninja.utils.ResponseStreams)1 Before (org.junit.Before)1