Search in sources :

Example 6 with Content

use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.

the class JettyServerProvider method addDefaultServices.

public void addDefaultServices() {
    addServlet("/error/*", new ErrorServlet());
    addBehaviour("/content/*", new Content());
    addBehaviour("/stutter/*", new Stutter());
    addBehaviour("/pause/*", new Pause(), new Content());
    addBehaviour("/truncate/*", new Truncate());
    addBehaviour("/timeout/*", new Pause());
    addBehaviour("/redirect/*", new Redirect(), new Content());
}
Also used : Pause(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Pause) Content(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content) Truncate(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Truncate) Redirect(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Redirect) Stutter(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Stutter)

Example 7 with Content

use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.

the class JettyServerProviderIT method testBehaviour.

@Test
public void testBehaviour() throws Exception {
    provider.addBehaviour("/behave/*", new Pause(550), new Content());
    long begin = System.currentTimeMillis();
    URL url = new URL("http://localhost:" + provider.getPort() + "/behave/baby");
    URLConnection conn = url.openConnection();
    InputStream in = conn.getInputStream();
    BufferedReader r = new BufferedReader(new InputStreamReader(in));
    String line = r.readLine();
    long end = System.currentTimeMillis();
    assertEquals("Received content was not correct.", "baby", line);
    assertTrue("expected 500ms, real delta: " + (end - begin), end - begin >= 500);
}
Also used : Pause(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Pause) InputStreamReader(java.io.InputStreamReader) Content(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Aggregations

Content (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content)7 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 Test (org.junit.Test)6 InetSocketAddress (java.net.InetSocketAddress)5 Proxy (java.net.Proxy)5 SocketAddress (java.net.SocketAddress)5 Debug (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Debug)5 Authenticator (java.net.Authenticator)3 PasswordAuthentication (java.net.PasswordAuthentication)3 Pause (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Pause)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URLConnection (java.net.URLConnection)1 Redirect (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Redirect)1 Stutter (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Stutter)1 Truncate (org.sonatype.goodies.httpfixture.server.jetty.behaviour.Truncate)1