@Test public void should_have_context_even_if_there_is_no_context_configured() throws Exception { server.response("foo"); running(server, new Runnable() { @Override public void run() throws Exception { String content = helper.get(remoteUrl("/context")); assertThat(content, is("foo")); } }); }
@Test public void should_return_expected_response() throws Exception { server.response("foo"); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.get(root()), is("foo")); } }); }
@Test public void should_return_expected_response_from_file() throws Exception { server.response(file("src/test/resources/foo.response")); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo.response")); } }); }
@Test public void should_return_expected_response_with_text_api() throws Exception { server.response(text("foo")); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo")); } }); }
@Test public void should_return_expected_response_from_path_resource() throws Exception { server.response(pathResource("foo.response")); running(server, new Runnable() { @Override public void run() throws Exception { assertThat(helper.get(root()), is("foo.response")); } }); }
@Test public void should_return_expected_version() throws Exception { server.response(version(VERSION_1_0)); running(server, new Runnable() { @Override public void run() throws IOException { ProtocolVersion version = helper.getResponse(root()).getProtocolVersion(); assertThat(version.getMajor(), is(1)); assertThat(version.getMinor(), is(0)); } }); }
@Test public void should_config_file_root() throws Exception { server.response(file("foo.response")); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo.response")); } }); }
@Test public void should_return_expected_response_with_content_api() throws Exception { server.response(with("foo")); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo")); } }); }
@Test public void should_return_excepted_version_with_version_api() throws Exception { server.response(version(VERSION_1_0)); running(server, new Runnable() { @Override public void run() throws IOException { ProtocolVersion version = helper.getResponse(root()).getProtocolVersion(); assertThat(version.getMajor(), is(1)); assertThat(version.getMinor(), is(0)); } }); }
@Test public void should_return_expected_status_code() throws Exception { server.response(status(200)); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.getForStatus(root()), is(200)); } }); }
@Test public void should_return_expected_header() throws Exception { server.response(header(HttpHeaders.CONTENT_TYPE, "application/json")); running(server, new Runnable() { @Override public void run() throws IOException { String value = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertThat(value, is("application/json")); } }); }
@Test public void should_return_default_content_type() throws Exception { server.response(with("foo")); running(server, new Runnable() { @Override public void run() throws Exception { Header header = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/plain; charset=utf-8")); } }); }
@Test public void should_return_template_from_file_root() throws Exception { server.response(template(file("foo.response"))); running(server, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo.response")); } }); }
@Test public void should_return_specified_content_type() throws Exception { server.response(with("foo"), header(HttpHeaders.CONTENT_TYPE, "text/html")); running(server, new Runnable() { @Override public void run() throws Exception { Header header = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/html")); } }); }
@Test public void should_return_template_header_from_file_root() throws Exception { server.response(header("foo", template(file("foo.response")))); running(server, new Runnable() { @Override public void run() throws IOException { org.apache.http.HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("foo.response")); } }); }
@Before public void setup() { HttpServer server = httpServer(port()); server.response("foo"); runner = Runner.runner(server); runner.start(); helper = new MocoTestHelper(); }
@Before public void setUp() throws Exception { super.setUp(); httpServer = httpServer(12306, context("/foo")); httpServer.response("foo"); anotherServer = httpServer(12306, context("/bar")); }
@Test public void should_config_handler_correctly_other_side_while_merging() throws Exception { httpServer = httpServer(12306, fileRoot("src/test/resources")); httpServer.response(file("foo.response")); HttpServer mergedServer = ((ActualHttpServer) httpServer).mergeServer((ActualHttpServer) anotherServer); running(mergedServer, new Runnable() { @Override public void run() throws IOException { assertThat(helper.get(root()), is("foo.response")); } }); }
@Test public void should_match_global_header_with_any_response() throws Exception { server = httpServer(port(), request(eq(header("foo"), "bar"))); server.response("blah"); running(server, new Runnable() { @Override public void run() throws Exception { String result = helper.getWithHeader(root(), of("foo", "bar")); assertThat(result, is("blah")); } }); }
@Test public void should_return_all_response_for_status_with_header() throws Exception { server = httpServer(port(), response(header("foo", "bar"))); server.response(status(200)); running(server, new Runnable() { @Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } }); }