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"));
}
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));
}
}
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());
}
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"));
}
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"));
}
}
}
Aggregations