コード例 #1
0
  @Test
  public void testSimpleServlet() throws IOException {
    SimpleWebServer server = new SimpleWebServer(9999);

    server.addServlet(new HelloWorldServlet(), "/test");

    server.start();

    String result = readURL("http://127.0.0.1:9999/test");

    server.stop();

    Assert.assertEquals("Hello world!\n", result);
  }
コード例 #2
0
  @Ignore
  @Test
  public void testSimpleServletPost() throws IOException {
    SimpleWebServer server = new SimpleWebServer(9876);

    server.addServlet(new HelloWorldServlet(), "/test");

    server.start();

    String result = readURL("http://localhost:9876/test");

    postToURL("http://localhost:9876/test", "switch=true&");

    String result2 = readURL("http://localhost:9876/test");

    server.stop();

    Assert.assertEquals("Hello world!\n", result);
    Assert.assertEquals("Goodbye world!\n", result2);
  }