Example #1
0
  public void testFileItemPersistence() throws Exception {
    // TODO: write a synchronous connector?
    byte[] testData = new byte[1024];
    for (int i = 0; i < testData.length; i++) testData[i] = (byte) i;

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new FileItemPersistenceTestServlet()), "/");
    server.addHandler(handler);

    server.start();

    localPort = connector.getLocalPort();

    try {
      WebClient wc = new WebClient();
      HtmlPage p = (HtmlPage) wc.getPage("http://localhost:" + localPort + '/');
      HtmlForm f = p.getFormByName("main");
      HtmlFileInput input = (HtmlFileInput) f.getInputByName("test");
      input.setData(testData);
      f.submit();
    } finally {
      server.stop();
    }
  }
 public int getPort() {
   return sock.getLocalPort();
 }