Package com.volantis.shared.net.http.cookies

Examples of com.volantis.shared.net.http.cookies.CookieImpl


        request.setCookies(cookies);

        HTTPMessageEntities entities = factory.createCookies(request);

        Cookie cookieArray [] = new Cookie[2];
        cookieArray[0] = new CookieImpl("One", null, null);
        cookieArray[1] = new CookieImpl("Two", null, null);

        // enusre that a SimpleHTTPMessageEntities is factored
        assertEquals("createCookies should return a " +
                     "SimpleHTTPMessageEntities instance",
                     SimpleHTTPMessageEntities.class,
View Full Code Here


                    "TEST", "test.domain", "/testdir");
            checkEquality(entity);
        }
        {
            // test WebRequestCookie
            CookieImpl entity = new WebRequestCookie();
            entity.setName("TEST");
            entity.setMaxAge(1);
            entity.setComment("comment");
            entity.setValue("test");
            checkEquality(entity);
        }
        {
            // test WebRequestHeader
            HeaderImpl entity = new WebRequestHeader();
            entity.setName("TEST");
            entity.setValue("test");
            checkEquality(entity);
        }
        {
            // test WebRequestParameter
            RequestParameterImpl entity = new WebRequestParameter();
            entity.setName("TEST");
            entity.setValue("test");
            checkEquality(entity);
        }

    }
View Full Code Here

     * @param maxAge - max age of the coookie
     * @return new Cookie                               
     */
    private Cookie createCookie(String name, String domain, String path,
                                String value, int maxAge) {
        CookieImpl cookie = new CookieImpl(name, domain, path);
        cookie.setValue(value);
        cookie.setMaxAge(maxAge);
        return cookie;
    }
View Full Code Here

        CookieImpl[] cookies = new CookieImpl[2];
        int count = 0;
        Iterator cookiesIterator = responseCookies.iterator();
        while (cookiesIterator.hasNext()) {
            CookieImpl cookie = (CookieImpl) cookiesIterator.next();
            cookies[count] = cookie;
            count++;
        }

        assertEquals("Checking cookie 1 name", "name1",
View Full Code Here

        String cookieName = "Set-Cookie";
        String cookieValue = "name1=value1";
        CookieVersion cookieVersion = CookieVersion.RFC2109;

        final Cookie cookieHeader =
                    new CookieImpl(cookieName, "localhost", ".");
        cookieHeader.setValue(cookieValue);
        cookieHeader.setVersion(cookieVersion);

        String headerName = "Other-Header";
        String headerValue = "o-h-value";
        final Header otherHeader = new HeaderImpl(headerName);
        otherHeader.setValue(headerValue);

        String method = "populateWebDriverResponse";
        Class paramTypes [] = {
            WebDriverResponse.class,
            HTTPResponseAccessor.class,
            HTTPMessageEntities.class};
        Object args [] = {
            response,
            new HTTPResponseAccessor() {
                public HTTPMessageEntities getCookies() {
                    HTTPMessageEntities cookies =
                                new SimpleHTTPMessageEntities();
                    cookies.add(cookieHeader);
                    return cookies;
                }

                public HTTPMessageEntities getHeaders() {
                    HTTPMessageEntities headers =
                                new SimpleHTTPMessageEntities();
                    headers.add(otherHeader);
                    return headers;
                }

                public InputStream getResponseStream() {
                    return null;
                }

                public int getStatusCode() {
                    return 200;
                }

                /**
                 * Get the HTTP version returned by the server.
                 * @return The HTTP version returned by the server.
                 */
                public HTTPVersion getHTTPVersion() {
                    return HTTPVersion.HTTP_1_1;
                }

            },
            new SimpleHTTPMessageEntities()
        };
        PrivateAccessor.invoke(manager, method, paramTypes, args);

        HTTPMessageEntities responseHeaders = response.getHeaders();
        HTTPMessageEntities responseCookies = response.getCookies();

        assertTrue("Expected one header.", responseHeaders.size() == 1);
        assertTrue("Expected one cookies.", responseCookies.size() == 1);

        Iterator headers = responseHeaders.iterator();
        while (headers.hasNext()) {
            HeaderImpl header = (HeaderImpl) headers.next();
            assertEquals("Unexpected header name.",
                         headerName, header.getName());
            assertEquals("Unexpected header value.",
                         headerValue, header.getValue());
        }

        Iterator cookiesIterator = responseCookies.iterator();
        while (cookiesIterator.hasNext()) {
            CookieImpl cookie = (CookieImpl) cookiesIterator.next();
            assertEquals("Checking cookie name",
                         cookieName,
                         cookie.getName());
            assertEquals("Checking cookie value",
                         cookieValue,
                         cookie.getValue());
            assertEquals("checking cookie version",
                         cookieVersion,
                         cookie.getVersion());
        }
    }
View Full Code Here

        WebDriverAccessor accessor = createWebDriverAccessor(request, response);
        container.setProperty(WebDriverAccessor.class, accessor, false);

        String cookieName = "Set-Cookie";
        String cookieValue = "name1=value1";
        final Cookie cookie1 = new CookieImpl(cookieName, "localhost", "/");
        cookie1.setValue(cookieValue);

        String headerName = "Other-Header";
        String headerValue = "o-h-value";
        final Header otherHeader = new HeaderImpl(headerName);
        otherHeader.setValue(headerValue);

        HTTPMessageEntities additionalCookies = new SimpleHTTPMessageEntities();
        Cookie additionalCookie = new CookieImpl("additionalName",
                                                 "localhost",
                                                 "/");
        additionalCookie.setValue("additionalValue");
        additionalCookies.add(additionalCookie);

        String method = "populateWebDriverResponse";

        Class paramTypes [] = {
            WebDriverResponse.class,
            HTTPResponseAccessor.class,
            HTTPMessageEntities.class};

        Object[] args  = {
            response,
            new HTTPResponseAccessor() {
                public HTTPMessageEntities getCookies() {
                    HTTPMessageEntities cookies =
                                new SimpleHTTPMessageEntities();
                    cookies.add(cookie1);
                    return cookies;
                }

                public HTTPMessageEntities getHeaders() {
                    HTTPMessageEntities headers =
                                new SimpleHTTPMessageEntities();
                    headers.add(otherHeader);
                    return headers;
                }

                public InputStream getResponseStream() {
                    return null;
                }

                public int getStatusCode() {
                    return 200;
                }

                /**
                 * Get the HTTP version returned by the server.
                 * @return The HTTP version returned by the server.
                 */
                public HTTPVersion getHTTPVersion() {
                    return HTTPVersion.HTTP_1_1;
                }
            },
            additionalCookies
        };
        PrivateAccessor.invoke(manager, method, paramTypes, args);

        HTTPMessageEntities responseHeaders = response.getHeaders();
        HTTPMessageEntities responseCookies = response.getCookies();

        final int expectedCookies = 2;
        assertEquals("Expected one header.", 1, responseHeaders.size());
        assertEquals("Expected number of cookies to match", expectedCookies,
                     responseCookies.size());

        Iterator headers = responseHeaders.iterator();
        while (headers.hasNext()) {
            HeaderImpl header = (HeaderImpl) headers.next();
            assertEquals("Unexpected header name.",
                         headerName, header.getName());
            assertEquals("Unexpected header value.",
                         headerValue, header.getValue());
        }

        CookieImpl[] cookies = new CookieImpl[expectedCookies];

        int count = 0;
        Iterator cookiesIterator = responseCookies.iterator();
        while (cookiesIterator.hasNext()) {
            CookieImpl cookie = (CookieImpl) cookiesIterator.next();
            cookies[count] = cookie;
            count++;
        }

        assertEquals("Checking cookie 1 name",
View Full Code Here

        return new SimpleHTTPMessageEntities();
    }

    // javadoc inherited
    public Cookie createCookie(String name, String domain, String path) {
        return new CookieImpl(name, domain, path);
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.cookies.CookieImpl

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.