Search in sources :

Example 26 with Matchers.containsString

use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.

the class HttpServerTestBase method testSimple.

@Test
public void testSimple() throws Exception {
    configureServer(new HelloWorldHandler());
    try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort())) {
        OutputStream os = client.getOutputStream();
        os.write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
        os.flush();
        // Read the response.
        String response = readResponse(client);
        Assert.assertThat(response, Matchers.containsString("HTTP/1.1 200 OK"));
        Assert.assertThat(response, Matchers.containsString("Hello world"));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

Matchers.containsString (org.hamcrest.Matchers.containsString)26 Test (org.junit.Test)24 Socket (java.net.Socket)12 OutputStream (java.io.OutputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ServletOutputStream (javax.servlet.ServletOutputStream)9 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4 InputStream (java.io.InputStream)3 ByteBuffer (java.nio.ByteBuffer)3 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)3 AbstractLogger (org.eclipse.jetty.util.log.AbstractLogger)3 SSLSocket (javax.net.ssl.SSLSocket)2 ServletInputStream (javax.servlet.ServletInputStream)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2