Search in sources :

Example 21 with Matchers.containsString

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

the class SniSslConnectionFactoryTest method testWildSNIConnect.

@Test
public void testWildSNIConnect() throws Exception {
    String response = getResponse("domain.com", "www.domain.com", "*.domain.com");
    Assert.assertThat(response, Matchers.containsString("X-HOST: www.domain.com"));
    response = getResponse("domain.com", "domain.com", "*.domain.com");
    Assert.assertThat(response, Matchers.containsString("X-HOST: domain.com"));
    response = getResponse("www.domain.com", "www.domain.com", "*.domain.com");
    Assert.assertThat(response, Matchers.containsString("X-HOST: www.domain.com"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 22 with Matchers.containsString

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

the class ResourceHandlerTest method testBigger.

@Test
public void testBigger() throws Exception {
    try (Socket socket = new Socket("localhost", _connector.getLocalPort())) {
        socket.getOutputStream().write("GET /resource/bigger.txt HTTP/1.0\n\n".getBytes());
        Thread.sleep(1000);
        String response = IO.toString(socket.getInputStream());
        Assert.assertThat(response, Matchers.startsWith("HTTP/1.1 200 OK"));
        Assert.assertThat(response, Matchers.containsString("   400\tThis is a big file" + LN + "     1\tThis is a big file"));
        Assert.assertThat(response, Matchers.endsWith("   400\tThis is a big file" + LN));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) Test(org.junit.Test)

Example 23 with Matchers.containsString

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

the class ServletContextHandlerTest method testInitOrder.

@Test
public void testInitOrder() throws Exception {
    ServletContextHandler context = new ServletContextHandler();
    ServletHolder holder0 = context.addServlet(TestServlet.class, "/test0");
    ServletHolder holder1 = context.addServlet(TestServlet.class, "/test1");
    ServletHolder holder2 = context.addServlet(TestServlet.class, "/test2");
    holder1.setInitOrder(1);
    holder2.setInitOrder(2);
    context.setContextPath("/");
    _server.setHandler(context);
    _server.start();
    assertEquals(2, __testServlets.get());
    String response = _connector.getResponses("GET /test1 HTTP/1.0\r\n\r\n");
    Assert.assertThat(response, Matchers.containsString("200 OK"));
    assertEquals(2, __testServlets.get());
    response = _connector.getResponses("GET /test2 HTTP/1.0\r\n\r\n");
    Assert.assertThat(response, containsString("200 OK"));
    assertEquals(2, __testServlets.get());
    assertThat(holder0.getServletInstance(), nullValue());
    response = _connector.getResponses("GET /test0 HTTP/1.0\r\n\r\n");
    assertThat(response, containsString("200 OK"));
    assertEquals(3, __testServlets.get());
    assertThat(holder0.getServletInstance(), notNullValue(Servlet.class));
    _server.stop();
    assertEquals(0, __testServlets.get());
    holder0.setInitOrder(0);
    _server.start();
    assertEquals(3, __testServlets.get());
    assertThat(holder0.getServletInstance(), notNullValue(Servlet.class));
    _server.stop();
    assertEquals(0, __testServlets.get());
}
Also used : HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 24 with Matchers.containsString

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

the class HttpFieldsTest method testPutTo.

@Test
public void testPutTo() throws Exception {
    HttpFields header = new HttpFields();
    header.put("name0", "value0");
    header.put("name1", "value:A");
    header.add("name1", "value:B");
    header.add("name2", "");
    ByteBuffer buffer = BufferUtil.allocate(1024);
    BufferUtil.flipToFill(buffer);
    HttpGenerator.putTo(header, buffer);
    BufferUtil.flipToFlush(buffer, 0);
    String result = BufferUtil.toString(buffer);
    assertThat(result, Matchers.containsString("name0: value0"));
    assertThat(result, Matchers.containsString("name1: value:A"));
    assertThat(result, Matchers.containsString("name1: value:B"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 25 with Matchers.containsString

use of org.hamcrest.Matchers.containsString in project elasticsearch by elastic.

the class ScriptContextRegistryTests method testValidateCustomScriptContextsPluginName.

public void testValidateCustomScriptContextsPluginName() throws IOException {
    for (final String rejectedContext : ScriptContextRegistry.RESERVED_SCRIPT_CONTEXTS) {
        try {
            //try to register a prohibited script context
            new ScriptContextRegistry(Collections.singleton(new ScriptContext.Plugin(rejectedContext, "test")));
            fail("ScriptContextRegistry initialization should have failed");
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), Matchers.containsString("[" + rejectedContext + "] is a reserved name, it cannot be registered as a custom script context"));
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString)

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