@Test
public void testPortRanges() throws Exception {

  WebApp app = WebApps.$for("test", this).start();
  String baseUrl = baseUrl(app);
  WebApp app1 = null;
  WebApp app2 = null;
  WebApp app3 = null;
  WebApp app4 = null;
  WebApp app5 = null;
  try {
    int port =  ServerSocketUtil.waitForPort(48000, 60);
    assertEquals("foo", getContent(baseUrl +"test/foo").trim());
    app1 = WebApps.$for("test", this).at(port).start();
    assertEquals(port, app1.getListenerAddress().getPort());
    app2 = WebApps.$for("test", this).at("0.0.0.0", port, true).start();
    assertTrue(app2.getListenerAddress().getPort() > port);
    Configuration conf = new Configuration();
    port =  ServerSocketUtil.waitForPort(47000, 60);
    app3 = WebApps.$for("test", this).at(port).withPortRange(conf, "abc").
        start();
    assertEquals(port, app3.getListenerAddress().getPort());
    ServerSocketUtil.waitForPort(46000, 60);
    conf.set("abc", "46000-46500");
    app4 = WebApps.$for("test", this).at(port).withPortRange(conf, "abc").
        start();
    assertEquals(46000, app4.getListenerAddress().getPort());
    app5 = WebApps.$for("test", this).withPortRange(conf, "abc").start();
    assertTrue(app5.getListenerAddress().getPort() > 46000);
  } finally {
    stopWebApp(app);
    stopWebApp(app1);
    stopWebApp(app2);
    stopWebApp(app3);
    stopWebApp(app4);
    stopWebApp(app5);
  }
}