Search in sources :

Example 41 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class HttpRequestFilteringTest method testContextsActive.

@Test
public void testContextsActive() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    WebClient client = new WebClient();
    Assert.assertEquals("true", client.getPage(fooContextPath + "/foo.html").getWebResponse().getContentAsString());
    Assert.assertEquals("true", client.getPage(barContextPath + "/foo.html").getWebResponse().getContentAsString());
    Assert.assertEquals("true", client.getPage(barContextPath + "/foo.css").getWebResponse().getContentAsString());
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 42 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project mvc-tck by mvc-spec.

the class ReturnTypeTest method responseWithNullEntity.

/**
 * A JAX-RS Response whose entity's type is one of the above
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "return-response")
public void responseWithNullEntity() throws IOException {
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/return/response-null").getWebResponse();
    // null entity
    assertThat(response.getStatusCode(), equalTo(200));
    assertThat(response.getContentAsString(), containsString("Some rendered view"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 43 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project mvc-tck by mvc-spec.

the class ReturnTypeTest method responseWithStringEntity.

/**
 * A JAX-RS Response whose entity's type is one of the above
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "return-response")
public void responseWithStringEntity() throws IOException {
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/return/response-string").getWebResponse();
    // string entity
    assertThat(response.getStatusCode(), equalTo(200));
    assertThat(response.getContentAsString(), containsString("Some rendered view"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 44 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project mvc-tck by mvc-spec.

the class ReturnTypeTest method voidWithoutViewAnnotation.

/**
 * A controller method that returns void is REQUIRED to be decorated by @View
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "return-void")
public void voidWithoutViewAnnotation() throws IOException {
    // prepare client not fail for 500 status code
    WebClient client = new WebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    // void without @View must not work
    Page page = client.getPage(baseUrl.toString() + "mvc/return/void-no-view");
    assertThat("Expected status code != 204", page, notNullValue());
    assertThat(page.getWebResponse().getStatusCode(), equalTo(500));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 45 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project mvc-tck by mvc-spec.

the class ReturnTypeTest method stringWithNullResult.

/**
 * The default view MUST be used only when such a non-void controller method returns a null value
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "non-null-viewable")
public void stringWithNullResult() throws IOException {
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/return/string-null").getWebResponse();
    // return null from string method uses @View
    assertThat(response.getStatusCode(), equalTo(200));
    assertThat(response.getContentAsString(), containsString("Some rendered view"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)182 Test (org.junit.Test)110 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)55 Page (com.gargoylesoftware.htmlunit.Page)33 TextPage (com.gargoylesoftware.htmlunit.TextPage)21 Before (org.junit.Before)20 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)17 URL (java.net.URL)14 JsonObject (javax.json.JsonObject)13 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)13 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)12 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)11 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)10 ReadContext (com.jayway.jsonpath.ReadContext)10 File (java.io.File)9 IOException (java.io.IOException)8 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)7 Test (org.junit.jupiter.api.Test)7 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)6 DefaultCredentialsProvider (com.gargoylesoftware.htmlunit.DefaultCredentialsProvider)5