Search in sources :

Example 1 with ResponseValidator

use of com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator in project vespa by vespa-engine.

the class HttpServerTest method requireThatFormPostKeepsContentWhenConfiguredTo.

@Test
public void requireThatFormPostKeepsContentWhenConfiguredTo() throws Exception {
    final TestDriver driver = newDriverWithFormPostContentRemoved(new ParameterPrinterRequestHandler(), false);
    final ResponseValidator response = driver.client().newPost("/status.html").addHeader(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED).setContent("foo=bar").execute();
    response.expectStatusCode(is(OK)).expectContent(is("{foo=[bar]}foo=bar"));
    assertThat(driver.close(), is(true));
}
Also used : ResponseValidator(com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator) Test(org.testng.annotations.Test)

Example 2 with ResponseValidator

use of com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator in project vespa by vespa-engine.

the class HttpServerTest method requireThatUnknownFormCharsetIsTreatedAsBadRequest.

@Test
public void requireThatUnknownFormCharsetIsTreatedAsBadRequest() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(new ParameterPrinterRequestHandler());
    final ResponseValidator response = driver.client().newPost("/status.html").addHeader(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED + ";charset=FLARBA-GARBA-7").setContent("a=b").execute();
    response.expectStatusCode(is(UNSUPPORTED_MEDIA_TYPE));
    assertThat(driver.close(), is(true));
}
Also used : ResponseValidator(com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator) Test(org.testng.annotations.Test)

Example 3 with ResponseValidator

use of com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator in project vespa by vespa-engine.

the class HttpServerTest method requireThatFormPostWithPercentEncodedContentIsDecoded.

@Test
public void requireThatFormPostWithPercentEncodedContentIsDecoded() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(new ParameterPrinterRequestHandler());
    final ResponseValidator response = driver.client().newPost("/status.html").addHeader(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED).setContent("%20%3D%C3%98=%22%25+").execute();
    response.expectStatusCode(is(OK)).expectContent(startsWith("{ =\u00d8=[\"% ]}"));
    assertThat(driver.close(), is(true));
}
Also used : ResponseValidator(com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator) Test(org.testng.annotations.Test)

Example 4 with ResponseValidator

use of com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator in project vespa by vespa-engine.

the class HttpServerTest method requireThatFormPostWorks.

@Test
public void requireThatFormPostWorks() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(new ParameterPrinterRequestHandler());
    final String requestContent = generateContent('a', 30);
    final ResponseValidator response = driver.client().newPost("/status.html").addHeader(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED).setContent(requestContent).execute();
    response.expectStatusCode(is(OK)).expectContent(startsWith('{' + requestContent + "=[]}"));
    assertThat(driver.close(), is(true));
}
Also used : ResponseValidator(com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.testng.annotations.Test)

Example 5 with ResponseValidator

use of com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator in project vespa by vespa-engine.

the class HttpServerTest method requireThatMultiPostWorks.

@Test
public void requireThatMultiPostWorks() throws Exception {
    // This is taken from tcpdump of bug 5433352 and reassembled here to see that httpserver passes things on.
    final String startTxtContent = "this is a test for POST.";
    final String updaterConfContent = "identifier                      = updater\n" + "server_type                     = gds\n";
    final TestDriver driver = TestDrivers.newInstance(new EchoRequestHandler());
    final ResponseValidator response = driver.client().newPost("/status.html").setMultipartContent(newFileBody("", "start.txt", startTxtContent), newFileBody("", "updater.conf", updaterConfContent)).execute();
    response.expectStatusCode(is(OK)).expectContent(containsString(startTxtContent)).expectContent(containsString(updaterConfContent));
}
Also used : ResponseValidator(com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.testng.annotations.Test)

Aggregations

ResponseValidator (com.yahoo.jdisc.http.server.jetty.SimpleHttpClient.ResponseValidator)20 Test (org.testng.annotations.Test)20 TestDriver (com.yahoo.jdisc.http.server.jetty.TestDriver)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3