Package ninja

Examples of ninja.Cookie


        assertEquals("mockedRemoteAddr", context.getRemoteAddr());
    }

    @Test
    public void testAddCookieViaResult() {
        Cookie cookie = Cookie.builder("cookie", "yum").setDomain("domain").build();
        context.init(servletContext, httpServletRequest, httpServletResponse);
        //context.addCookie(cookie);

        //generate an arbitrary result:
        Result result = Results.html();
View Full Code Here


    }

    @Test
    public void testThatFlashCookieWorksAndIsActiveOnlyOneTime() {
        // setup this testmethod
        Cookie cookie = Cookie.builder("NINJA_FLASH",
                "hello=flashScope").build();
        when(context.getCookie("NINJA_FLASH")).thenReturn(cookie);

        FlashScope flashCookie = new FlashScopeImpl(ninjaProperties);
View Full Code Here

    }

    @Test
    public void testThatFlashCookieClearWorks() {
        // setup this testmethod
        Cookie cookie = Cookie.builder("NINJA_FLASH",
                "hello=flashScope").build();
        when(context.getCookie("NINJA_FLASH")).thenReturn(cookie);

        FlashScope flashCookie = new FlashScopeImpl(ninjaProperties);
View Full Code Here

    }

    @Test
    public void testThatFlashCookieClearOfOutgoingWorks() {
        // setup this testmethod
        Cookie cookie = Cookie.builder("NINJA_FLASH",
                "hello=flashScope").build();
        when(context.getCookie("NINJA_FLASH")).thenReturn(cookie);

        FlashScope flashCookie = new FlashScopeImpl(ninjaProperties);
View Full Code Here

    }

    @Test
    public void testThatFlashCookieKeepWorks() {
        // setup this testmethod
        Cookie cookie = Cookie.builder("NINJA_FLASH",
                "hello=flashScope").build();
        when(context.getCookie("NINJA_FLASH")).thenReturn(cookie);

        FlashScope flashCookie = new FlashScopeImpl(ninjaProperties);
View Full Code Here

        // a cookie will be set
        verify(result).addCookie(cookieCaptor.capture());

        // now we simulate a new request => the session storage will generate a
        // new cookie:
        Cookie newSessionCookie = Cookie.builder(
                cookieCaptor.getValue().getName(),
                cookieCaptor.getValue().getValue()).build();

        // that will be returned by the httprequest...
        when(context.getCookie(cookieCaptor.getValue().getName())).thenReturn(
View Full Code Here

   
    @Override
    public void clearLanguage(Result result) {

        Cookie defaultLangCookie = generateNinjaLanguageCookie();       
        result.unsetCookie(defaultLangCookie.getName());

    }
View Full Code Here

   
    @Override
    public Result setLanguage(String locale, Result result) {
       
        Cookie defaultLangCookie = generateNinjaLanguageCookie();       
        Cookie cookie = Cookie.builder(defaultLangCookie).setValue(locale).build();   
        result.addCookie(cookie);
       
        return result;

    }
View Full Code Here

   

    @Override
    public Optional<String> getLanguage(Context context, Optional<Result> result) {
       
        Cookie defaultCookie = generateNinjaLanguageCookie();
       
       
        // Step 1: Determine language from result.
        // Result always has priority over context and will overwrite context.
        if (result.isPresent()) {
            Cookie cookie = result.get().getCookie(defaultCookie.getName());
       
            if (cookie != null) {
           
                if (cookie.getValue() != null
                        && !cookie.getValue().isEmpty()) {
               
                    //forced language is:
                    return Optional.of(cookie.getValue());
                }
           
            }
        }
       
        // Step 2 => we did not find the language in the result
        // We try to determine it from the context.
        Cookie cookie = context.getCookie(defaultCookie.getName());

        if (cookie != null) {
           
            if (cookie.getValue() != null
                    && !cookie.getValue().isEmpty()) {
                //forced language is:
                return Optional.of(cookie.getValue());
            }
           
        } 
       
        // Step 3: Determine language from Accept-Language header.
View Full Code Here

        javax.servlet.http.Cookie[] servletCookies = httpServletRequest.getCookies();
        List<Cookie> ninjaCookies = new ArrayList<>(servletCookies.length);

        for (javax.servlet.http.Cookie cookie : servletCookies) {
            Cookie ninjaCookie = CookieHelper.convertServletCookieToNinjaCookie(cookie);
            ninjaCookies.add(ninjaCookie);
        }

        return ninjaCookies;
    }
View Full Code Here

TOP

Related Classes of ninja.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.