Package edu.wpi.cs.wpisuitetng.network.dummyserver

Examples of edu.wpi.cs.wpisuitetng.network.dummyserver.DummyServer


    // The request body
    String body = "This is the request body!";

    // Create the URL
    try {
      DummyServer server = new DummyServer(port);
      server.start();

      // Make a new POST Request.
      Request manualRequest = new Request(config, null, HttpMethod.POST)// construct the Request

      // Configure the request
      manualRequest.setBody(body)// set the request body to send to the server
      manualRequest.addObserver(requestObserver)// Add the requestObserver to the request's set of Observers

      // Send the request!
      manualRequest.send();
      synchronized (requestObserver) {
        requestObserver.wait(2000);
      }

      //assertEquals(true, (body+"\n").equals(manualRequest.getResponse().getBody()));
      assertEquals(200, manualRequest.getResponse().getStatusCode());
      assertEquals(true, "OK".equalsIgnoreCase(manualRequest.getResponse().getStatusMessage()));
     
      assertTrue(body.equals(server.getLastReceived().getBody()));
      assertEquals(manualRequest.getHttpMethod(), server.getLastReceived().getHttpMethod());
     
      server.stop();
    } //TODO switch to https
    catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
View Full Code Here


  @Test
  public void testRequestResponseCode400Plus() {
    // The response body
    String body = "Some error";

    DummyServer server = new DummyServer(port);

    // Construct and configure a canned response for the server to return
    ResponseModel cannedResponse = new ResponseModel();
    cannedResponse.setStatusCode(400)// status code: 400
    cannedResponse.setBody(body)// body: "Some error"

    // Make a new POST Request.
    Request manualRequest = new Request(config, null, HttpMethod.POST);   // construct the Request
    manualRequest.setBody(body)// set the request body to send to the server
    manualRequest.clearAsynchronous()// make this request synchronously so that the test is blocked

    // set the canned response and start the server
    server.setResponse(cannedResponse);
    server.start();

    // Send the request!
    manualRequest.send();

    assertTrue(manualRequest.getResponse().getBody().contains(body))// check that the message in the body was read
    assertEquals(400, manualRequest.getResponse().getStatusCode());

    assertTrue(body.equals(server.getLastReceived().getBody()));
    assertEquals(manualRequest.getHttpMethod(), server.getLastReceived().getHttpMethod());

    server.stop();
  }
View Full Code Here

TOP

Related Classes of edu.wpi.cs.wpisuitetng.network.dummyserver.DummyServer

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.