Package org.eclipse.ecf.internal.tests.filetransfer.httpserver

Examples of org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer


   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    super.setUp();
    tmpFile = File.createTempFile("ECFTest", "");
    server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

      public boolean processRequest(SimpleHttpServerConnection conn,
          SimpleRequest request) throws IOException {
View Full Code Here


        });
        event.connectUsingJob(connectJob);
      }
    };

    final SimpleServer server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

      public boolean processRequest(SimpleHttpServerConnection conn,
          SimpleRequest request) throws IOException {
        trace("Not responding to request " + request.getRequestLine());
        return stalledInRequestHandler(doCancel);
      }

    });
    try {
      // path does not matter as server does not respond.
      testReceive(server.getServerURL() + "/foo", lw);

      assertHasEvent(startConnectEvents,
          IFileTransferConnectStartEvent.class);
      assertHasNoEvent(startEvents,
          IIncomingFileTransferReceiveStartEvent.class);
      assertHasNoEvent(dataEvents,
          IIncomingFileTransferReceiveDataEvent.class);
      IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
      assertTrue(doneEvent.getException().toString(),
          doneEvent.getException() instanceof UserCancelledException);
      assertTrue(doneEvent.getSource().isDone());
      assertSame(doneEvent.getException(), doneEvent.getSource()
          .getException());

      assertNull(tmpFile);

      assertFalse(socketInReadWrapper.inRead);
      socketEvents.validateOneSocketCreatedAndClosed();

    } finally {
      server.shutdown();
    }
  }
View Full Code Here

          fail(e.toString());
        }
      }
    };

    final SimpleServer server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

      public boolean processRequest(SimpleHttpServerConnection conn,
          SimpleRequest request) throws IOException {
        trace("Responding to request but never provide full body"
            + request.getRequestLine());
        ResponseWriter w = conn.getWriter();
        writeLines(w, new String[] { "HTTP/1.0 200 OK",
            "Content-Length: 9",
            "Content-Type: text/plain; charset=UTF-8", "" });
        w.flush();
        synchronized (doCancel) {
          doCancel[0] = Boolean.TRUE;
        }

        conn.setKeepAlive(true);
        //
        return stalledInRequestHandler(doCancel);
      }

    });
    try {
      // path does not matter as server does not respond.
      testReceive(server.getServerURL() + "/foo", lw);

      assertHasEvent(startConnectEvents,
          IFileTransferConnectStartEvent.class);
      assertHasEvent(startEvents,
          IIncomingFileTransferReceiveStartEvent.class);
      assertDoneCancelled();

      assertNotNull(tmpFile);
      assertTrue(tmpFile.exists());
      assertEquals(0, tmpFile.length());

      assertFalse(socketInReadWrapper.inRead);
      socketEvents.validateOneSocketCreatedAndClosed();
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

        }

      }
    };

    final SimpleServer server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

      public boolean processRequest(SimpleHttpServerConnection conn,
          SimpleRequest request) throws IOException {
        trace("Responding to request but never provide only 50% of body"
            + request.getRequestLine());
        ResponseWriter w = conn.getWriter();
        writeLines(w, new String[] { "HTTP/1.0 200 OK",
            "Content-Length: " + len,
            "Content-Type: text/plain; charset=UTF-8", "" });
        w.flush();
        for (int i = 0; i < len / 2; i++) {
          w.write("x");
        }
        w.flush();
        conn.setKeepAlive(true);
        try {
          // give it a bit of time to receive the data
          Thread.sleep(200);
        } catch (InterruptedException e) {
        }
        return stalledInRequestHandler(doCancel);
      }

    });
    try {
      // path does not matter as server does not respond.
      testReceive(server.getServerURL() + "/foo", lw);

      assertHasEvent(startConnectEvents,
          IFileTransferConnectStartEvent.class);
      assertHasEvent(startEvents,
          IIncomingFileTransferReceiveStartEvent.class);
      assertHasMoreThanEventCount(dataEvents,
          IIncomingFileTransferReceiveDataEvent.class, 0);
      assertDoneCancelled();

      assertNotNull(tmpFile);
      assertTrue(tmpFile.exists());
      assertEquals(len / 2, tmpFile.length());

      assertFalse(socketInReadWrapper.inRead);
      socketEvents.validateOneSocketCreatedAndClosed();

    } finally {
      server.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.