/** * Gets content from the path that's relative to the base URL on which the Arquillian test * archive is deployed. * * @param path the path relative to the URL on which the Arquillian test is deployed * @return the raw content as a string as returned by the server */ protected String getFromServerPath(final String path) { response = null; for (int i=0; i<=3; i++) { try { response = webClient.getPage(base + path).getWebResponse().getContentAsString(); if (!response.contains("The response wrapper must wrap the response obtained from getResponse()")) { return response; } } catch (FailingHttpStatusCodeException | IOException e) { throw new IllegalStateException(e); } } return response; }
@Test public void contextPathNull() throws IOException { this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient)); Page page = this.webClient.getPage("http://localhost/context/a"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); }
@Test public void contextPathEmpty() throws IOException { this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "")); Page page = this.webClient.getPage("http://localhost/context/a"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); }
@Test public void contextPathExplicit() throws IOException { this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "/context")); Page page = this.webClient.getPage("http://localhost/context/a"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); }
@Test public void forward() throws IOException { this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "")); Page page = this.webClient.getPage("http://localhost/forward"); assertThat(page.getWebResponse().getContentAsString(), equalTo("hello")); }
@Test public void verifyExampleInClassLevelJavadoc() throws Exception { Assume.group(TestGroup.PERFORMANCE); WebClient webClient = new WebClient(); MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build(); MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient); WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*"); WebConnection httpConnection = new HttpWebConnection(webClient); webClient.setWebConnection( new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection))); Page page = webClient.getPage("http://code.jquery.com/jquery-1.11.0.min.js"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString())); }
/** * {@inheritDoc} */ @Override protected boolean isJavaScriptInitializationNeeded() { return getScriptableObject() == null || !(getEnclosedPage().getWebResponse() instanceof StringWebResponse); // TODO: find a better way to distinguish content written by document.open(),... }
/** * Get the last WebResponse from HtmlUnit. */ public WebResponse getWebResponse() { return wc.getCurrentWindow().getEnclosedPage().getWebResponse(); }
private HistoryEntry(final Page page) { // verify cache-control header values before storing if (HeaderUtils.containsNoStore(page.getWebResponse())) { page_ = null; } else { page_ = new SoftReference<>(page); } final WebRequest request = page.getWebResponse().getWebRequest(); webRequest_ = new WebRequest(request.getUrl(), request.getHttpMethod()); webRequest_.setRequestParameters(request.getRequestParameters()); }
/** * {@inheritDoc} */ @Override protected boolean isJavaScriptInitializationNeeded() { final Page enclosedPage = getEnclosedPage(); return getScriptableObject() == null || enclosedPage.getUrl() == WebClient.URL_ABOUT_BLANK || !(enclosedPage.getWebResponse() instanceof StringWebResponse); // TODO: find a better way to distinguish content written by document.open(),... }
@Test(groups = { "el" } ) @SpecAssertion(section = "12.4", id = "a") public void testELResolverRegisteredWithServletContainer() throws Exception { WebClient webclient = new WebClient(); String content = webclient.getPage(getContextPath() + "JSPTestPage.jsp").getWebResponse().getContentAsString(); assert content.contains("Dolly"); } }
@Test public void testOnStartAsyncCalledSuccesfully() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_LOOP)); Page results = webClient.getPage(contextPath + "Status"); assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true")); assertTrue(results.getWebResponse().getContentAsString().contains("onStartAsync: true")); }
private void setUrl(final URL url) { if (url != null) { webRequest_.setUrl(url); final Page page = getPage(); if (page != null) { page.getWebResponse().getWebRequest().setUrl(url); } } }
/** * Returns this location's current URL. * @return this location's current URL */ private URL getUrl() { return window_.getWebWindow().getEnclosedPage().getWebResponse().getRequestSettings().getUrl(); }
@Test @Ignore //enable when WELD-1774 is fixed public void testOnErrorCalledSuccesfully() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(false); webClient.getPage(getPath(AsyncServlet.TEST_ERROR)); Page results = webClient.getPage(contextPath + "Status"); assertTrue(results.getWebResponse().getContentAsString(), results.getWebResponse().getContentAsString().contains("onError: true")); }
@Test public void testCrossContextForward(@ArquillianResource @OperateOnDeployment(FIRST) URL firstContext) throws IOException { Page page = new WebClient().getPage(firstContext + "forwarding"); assertEquals(200, page.getWebResponse().getStatusCode()); assertEquals("<h1>Hello World</h1>", page.getWebResponse().getContentAsString()); } }
@Test @SpecAssertions({ @SpecAssertion(section = EL, id = "a"), @SpecAssertion(section = NAME_RESOLUTION, id = "d"), @SpecAssertion(section = NAME_RESOLUTION_EE, id = "a"), @SpecAssertion(section = NAMES_EE, id = "a") }) public void testELResolverRegisteredWithServletContainer() throws Exception { WebClient webclient = new WebClient(); String content = webclient.getPage(contextPath + "JSPTestPage.jsp").getWebResponse().getContentAsString(); assert content.contains("Dolly"); } }
@Test public void testOnCompleteCalledSuccesfully() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE)); Page results = webClient.getPage(contextPath + "Status"); assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true")); }
private JSONObject callStepsToJson(String jenkinsFileContent) throws IOException { JenkinsRule.WebClient wc = j.createWebClient(); WebRequest req = new WebRequest(new URL(wc.getContextPath() + ModelConverterAction.PIPELINE_CONVERTER_URL + "/stepsToJson"), HttpMethod.POST); assertNotNull(jenkinsFileContent); NameValuePair pair = new NameValuePair("jenkinsfile", jenkinsFileContent); req.setRequestParameters(Collections.singletonList(pair)); String rawResult = wc.getPage(req).getWebResponse().getContentAsString(); assertNotNull(rawResult); return JSONObject.fromObject(rawResult); } }
private JSONObject callStepToJenkinsFile(String jsonFileName) throws IOException { JenkinsRule.WebClient wc = j.createWebClient(); WebRequest req = new WebRequest(new URL(wc.getContextPath() + ModelConverterAction.PIPELINE_CONVERTER_URL + "/stepsToJenkinsfile"), HttpMethod.POST); String simpleJson = fileContentsFromResources(jsonFileName); assertNotNull(simpleJson); NameValuePair pair = new NameValuePair("json", simpleJson); req.setRequestParameters(Collections.singletonList(pair)); String rawResult = wc.getPage(req).getWebResponse().getContentAsString(); assertNotNull(rawResult); return JSONObject.fromObject(rawResult); }