Package com.volantis.shared.net.http

Examples of com.volantis.shared.net.http.HTTPMessageEntities


    /**
     * tests the reateCookies method
     * @throws Exception if an error occurs
     */
    public void testCreateCookies() throws Exception {
        HTTPMessageEntities entities = factory.createCookies();
        // enusre that a SimpleHTTPMessageEntities is factored
        assertEquals("createCookies should return a " +
                     "SimpleHTTPMessageEntities instance",
                     SimpleHTTPMessageEntities.class,
                     entities.getClass());

        // ensure the HTTPMessageEntities has not been populated
        assertEquals("createCookies should return an empty " +
                     "HTTPMessageEntities",
                     0, entities.size());
    }
View Full Code Here


        javax.servlet.http.Cookie[] cookies = new javax.servlet.http.Cookie[2];
        cookies[0] = new javax.servlet.http.Cookie("One", "One");
        cookies[1] = new javax.servlet.http.Cookie("Two", "Two");
        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,
                     entities.getClass());

        // ensure the HTTPMessageEntities has been populated with 2
        // cookies
        assertEquals("entities should have a size of 2",
                     2, entities.size());

        HTTPMessageEntity[] entity =
                entities.remove(cookieArray[0].getIdentity());
        entity = entities.remove(cookieArray[1].getIdentity());

        // ensure the HTTPMessageEntities only contained the two cookies
        assertEquals("entities should now be empty ", 0, entities.size());

    }
View Full Code Here

        // =====================================================================
        //   Create Mocks
        // =====================================================================

        WebRequestCookie cookie = new WebRequestCookie();
        HTTPMessageEntities entities = new SimpleHTTPMessageEntities();

        // =====================================================================
        //   Set Expectations
        // =====================================================================
View Full Code Here

        //   Set Expectations
        // =====================================================================

        WebRequestParameter parameter = new WebRequestParameter();
        entityFactoryMock.expects.createParameter().returns(parameter);
        HTTPMessageEntities entities = new SimpleHTTPMessageEntities();
        entityFactoryMock.expects.createHTTPMessageEntities().returns(entities);

        expectAddSimpleElementProcess(parameter);

        contextMock.expects.getProperty(WebRequestParameter.class).returns(
View Full Code Here

        //   Set Expectations
        // =====================================================================

        WebRequestHeader header = new WebRequestHeader();
        entityFactoryMock.expects.createHeader().returns(header);
        HTTPMessageEntities entities = new SimpleHTTPMessageEntities();
        entityFactoryMock.expects.createHTTPMessageEntities().returns(entities);

        expectAddSimpleElementProcess(header);

        contextMock.expects.getProperty(WebRequestHeader.class).returns(null);
View Full Code Here

        CookieSpecBase cookieSpecBase = new CookieSpecBase();
        org.apache.commons.httpclient.Cookie[] cookiesArray =
                    cookieSpecBase.parse("www.volantis.com", 843, "/index", true,
                                         "name1=value1,name2=value2");

        HTTPMessageEntities responseCookies = new SimpleHTTPMessageEntities();

        String method = "addHttpClientCookiesToWebDriverCookies";
        Class paramTypes [] = {org.apache.commons.httpclient.Cookie[].class,
                               HTTPMessageEntities.class};
        Object args [] = {cookiesArray, responseCookies};
        PrivateAccessor.invoke(manager, method, paramTypes, args);


        assertTrue("Expected two cookies.", responseCookies.size() == 2);

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

        final org.apache.commons.httpclient.Header header =
                    new org.apache.commons.httpclient.Header();
        header.setName(headerName);
        header.setValue(headerValue);

        HTTPMessageEntities responseHeader = new SimpleHTTPMessageEntities();

        String method = "addHttpClientHeaderToWebDriverHeaders";
        Class paramTypes [] = {org.apache.commons.httpclient.Header.class,
                               HTTPMessageEntities.class,
                               boolean.class };
        Object args [] = {header, responseHeader, Boolean.valueOf(list)};
        PrivateAccessor.invoke(manager, method, paramTypes, args);

        Iterator headers = responseHeader.iterator();
        while (headers.hasNext()) {
            HeaderImpl headerImpl = (HeaderImpl) headers.next();
            assertEquals("Unexpected header name.",
                         headerName, headerImpl.getName());
            assertEquals("Unexpected header value.",
View Full Code Here

            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());
View Full Code Here

        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++;
        }
View Full Code Here

            }
        }

        // Add the entity to the collection of entities.
        XMLPipelineContext context = dynamicProcess.getPipelineContext();
        HTTPMessageEntities entities = getEntities(context);
        addProtocolMessageEntity(entities, entity);
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.HTTPMessageEntities

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.