Search in sources :

Example 46 with WebClient

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

the class ReturnTypeTest method voidWithViewAnnotation.

/**
 * A controller method that returns void is REQUIRED to be decorated by @View
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "return-void")
public void voidWithViewAnnotation() throws IOException {
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/return/void-with-view").getWebResponse();
    // void with @View renders the view referenced in the annotation
    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 47 with WebClient

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

the class SimpleTest method shouldDoStuff.

@Test
public void shouldDoStuff() throws IOException {
    Page page = new WebClient().getPage(baseUrl.toString() + "mvc/simple");
    Assert.assertThat(page.getWebResponse().getContentAsString(), CoreMatchers.containsString("Hello world!"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 48 with WebClient

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

the class ControllerAnnotationTest method controllerMethod.

/**
 * An MVC controller is a JAX-RS resource method decorated by @Controller
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "ctrl-method")
public void controllerMethod() throws IOException {
    // view rendered because method is a controller
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/method/view1").getWebResponse();
    assertThat(response.getStatusCode(), equalTo(200));
    assertThat(response.getContentAsString(), containsString("Rendered view #1"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 49 with WebClient

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

the class ControllerAnnotationTest method controllerClass.

/*
     * If this annotation is applied to a class, then all resource methods in it are regarded as controllers
     */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "ctrl-class")
public void controllerClass() throws IOException {
    WebClient client = new WebClient();
    // view rendered because method is a controller
    WebResponse response1 = client.getPage(baseUrl.toString() + "mvc/class/view1").getWebResponse();
    assertThat(response1.getStatusCode(), equalTo(200));
    assertThat(response1.getContentAsString(), containsString("Rendered view #1"));
    // view rendered because method is a controller
    WebResponse response2 = client.getPage(baseUrl.toString() + "mvc/class/view2").getWebResponse();
    assertThat(response2.getStatusCode(), equalTo(200));
    assertThat(response2.getContentAsString(), containsString("Rendered view #2"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 50 with WebClient

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

the class MediaTypeTest method defaultMediaType.

/**
 * Moreover, the default media type for a response is assumed to be text/html, but otherwise can be declared
 * using @Produces just like in JAX-RS
 */
@Test
@SpecAssertion(section = Sections.MVC_CONTROLLERS, id = "default-mediatype")
public void defaultMediaType() throws IOException {
    WebResponse response = new WebClient().getPage(baseUrl.toString() + "mvc/mediatype/default").getWebResponse();
    // default content-type of text/html
    assertThat(response.getStatusCode(), equalTo(200));
    assertThat(response.getContentType(), equalTo("text/html"));
    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