Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebRequest


        }
       
        public RequestAssertion(HttpMethod method, String path,
                RequestParameter...params) throws Exception {
           
            WebRequest wr = new WebRequest(new URL(toUrl(path)), method);
            setRequestParameters(wr, params);
            page = client.getPage(wr);
        }
View Full Code Here


        }
       
        public RequestAssertion(RequestBody content, RequestContentType contentType,
                String path) throws Exception {
           
            WebRequest wr = new WebRequest(new URL(toUrl(path)));
            wr.setHttpMethod(HttpMethod.POST);
            wr.setRequestBody(content.getBody());
            wr.setAdditionalHeader("Content-Type", contentType.getContentType());
            page = client.getPage(wr);
        }
View Full Code Here

    protected class HEADRequestAssertion {
       
        private Page page;
       
        public HEADRequestAssertion(String path) throws Exception {
            WebRequest wr = new WebRequest(new URL(toUrl(path)),
                    HttpMethod.HEAD);
            page = client.getPage(wr);
            assertNotNull(page);
        }
View Full Code Here

    }

    private OAuthToken getAccessToken(String refreshToken) throws IOException {
        final String tokenUrl = String.format(ACCESS_TOKEN_URL, refreshToken,
            oAuthParams.getRedirectUri(), oAuthParams.getClientId(), oAuthParams.getClientSecret());
        final WebRequest webRequest = new WebRequest(new URL(tokenUrl), HttpMethod.POST);

        final WebResponse webResponse = webClient.loadWebResponse(webRequest);
        if (webResponse.getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException(String.format("Error getting access token: [%s: %s]",
                webResponse.getStatusCode(), webResponse.getStatusMessage()));
View Full Code Here

        super.tearDown();
        webClient = null;
    }

    public void testReadCacheableResource() throws Exception {
        WebRequest webRequest = new WebRequest(new URL(
            "http://localhost/rfRes/org.richfaces.resource.CacheableResourceImpl.jsf"));

        webRequest.getAdditionalHeaders().put(ECHO_HEADER, "ping?");

        WebResponse webResponse = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, webResponse.getStatusCode());
        assertEquals(ResourceUtils.formatHttpDate(lastModified.getTime()), webResponse.getResponseHeaderValue("Last-Modified"));
        assertEquals(ResourceUtils.formatHttpDate(currentTime.getTime()), webResponse.getResponseHeaderValue("Date"));
        assertEquals(ResourceUtils.formatHttpDate(expires.getTime()), webResponse.getResponseHeaderValue("Expires"));
        assertEquals("max-age=1209600", webResponse.getResponseHeaderValue("Cache-Control"));
        assertTrue(webResponse.getResponseHeaderValue("Content-Type").startsWith("text/plain"));
        assertEquals("W/\"" + "ping?".length() + "-" + lastModified.getTime() + "\"",
            webResponse.getResponseHeaderValue("ETag"));
        assertNull(webResponse.getResponseHeaderValue("Pragma"));
        assertEquals("ping?", webResponse.getContentAsString("US-ASCII"));
        webRequest.getAdditionalHeaders().put(ECHO_HEADER, "pong");

        WebResponse cachedWebResponse = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, cachedWebResponse.getStatusCode());
        assertEquals("ping?", cachedWebResponse.getContentAsString("US-ASCII"));
        webRequest.getAdditionalHeaders().put(IF_MODIFIED_SINCE, ResourceUtils.formatHttpDate(currentTime));

        WebResponse cachedWebResponse2 = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_NOT_MODIFIED, cachedWebResponse2.getStatusCode());
    }
View Full Code Here

        assertEquals(HttpServletResponse.SC_NOT_MODIFIED, cachedWebResponse2.getStatusCode());
    }

    public void testReadNonCacheableResource() throws Exception {
        WebRequest webRequest = new WebRequest(new URL(
            "http://localhost/rfRes/org.richfaces.resource.NonCacheableResourceImpl.jsf"));

        webRequest.getAdditionalHeaders().put(ECHO_HEADER, "ping?");

        WebResponse webResponse = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, webResponse.getStatusCode());
        assertEquals(ResourceUtils.formatHttpDate(lastModified.getTime()), webResponse.getResponseHeaderValue("Last-Modified"));
        assertEquals(ResourceUtils.formatHttpDate(currentTime.getTime()), webResponse.getResponseHeaderValue("Date"));
        assertEquals("0", webResponse.getResponseHeaderValue("Expires"));
        assertEquals("max-age=0, no-store, no-cache", webResponse.getResponseHeaderValue("Cache-Control"));
        assertTrue(webResponse.getResponseHeaderValue("Content-Type").startsWith("text/plain"));
        assertNull(webResponse.getResponseHeaderValue("ETag"));
        assertEquals("no-cache", webResponse.getResponseHeaderValue("Pragma"));
        assertEquals("ping?", webResponse.getContentAsString("US-ASCII"));
        webRequest.getAdditionalHeaders().put(ECHO_HEADER, "pong");

        WebResponse cachedWebResponse = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, cachedWebResponse.getStatusCode());
        assertEquals("pong", cachedWebResponse.getContentAsString("US-ASCII"));
        webRequest.getAdditionalHeaders().put(IF_MODIFIED_SINCE, ResourceUtils.formatHttpDate(currentTime));

        WebResponse cachedWebResponse2 = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, cachedWebResponse2.getStatusCode());
    }
View Full Code Here

        assertEquals(HttpServletResponse.SC_OK, cachedWebResponse2.getStatusCode());
    }

    public void testNonExistingResource() throws Exception {
        WebRequest emptyResourceNameSettings = new WebRequest(new URL("http://localhost/rfRes/x.jsf"));
        WebResponse emptyResourceNameResponse = webClient.loadWebResponse(emptyResourceNameSettings);

        assertEquals(HttpServletResponse.SC_NOT_FOUND, emptyResourceNameResponse.getStatusCode());
    }
View Full Code Here

        assertEquals(HttpServletResponse.SC_NOT_FOUND, emptyResourceNameResponse.getStatusCode());
    }

    public void testDefaultMojarraResource() throws Exception {
        WebRequest mojarraWebRequest = new WebRequest(new URL(
            "http://localhost/javax.faces.resource/defaultResourceHandlerResource.js.jsf"));
        WebResponse mojarraResourceNameResponse = webClient.loadWebResponse(mojarraWebRequest);

        assertEquals(HttpServletResponse.SC_OK, mojarraResourceNameResponse.getStatusCode());
    }
View Full Code Here

        assertNotNull(Class.forName("org.richfaces.resource.MarkerFileResourceImpl", true, contextClassLoader));
        assertNotNull(contextClassLoader
            .getResource("META-INF/org.richfaces.resource.MarkerFileResourceImpl.resource.properties"));

        WebRequest markerFileWebRequest = new WebRequest(new URL(
            "http://localhost/rfRes/org.richfaces.resource.MarkerFileResourceImpl.jsf"));
        WebResponse markerFileResponse = webClient.loadWebResponse(markerFileWebRequest);

        assertEquals(HttpServletResponse.SC_OK, markerFileResponse.getStatusCode());
        assertNotNull(Class.forName("org.richfaces.resource.NoMarkerFileResourceImpl", true, contextClassLoader));
        assertNull(contextClassLoader
            .getResource("META-INF/org.richfaces.resource.NoMarkerFileResourceImpl.resource.properties"));

        WebRequest noMarkerFileRequestSettings = new WebRequest(new URL(
            "http://localhost/rfRes/org.richfaces.resource.NoMarkerFileResourceImpl.jsf"));
        WebResponse noMarkerResponse = webClient.loadWebResponse(noMarkerFileRequestSettings);

        assertEquals(HttpServletResponse.SC_NOT_FOUND, noMarkerResponse.getStatusCode());
    }
View Full Code Here

                injector.setInstance(ConfigurationService.class, new ConfigurationServiceImpl());
            }
        }));
        ServiceTracker.setFactory(injector);

        WebRequest webRequest = new WebRequest(new URL("http://localhost/rfRes/StateHolderResource.jsf?db=1"));
        WebResponse resourceResponse = webClient.loadWebResponse(webRequest);

        assertEquals(HttpServletResponse.SC_OK, resourceResponse.getStatusCode());
        assertEquals("test text", resourceResponse.getContentAsString("US-ASCII"));
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebRequest

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.