Search in sources :

Example 1 with LoggedRequest

use of com.github.tomakehurst.wiremock.verification.LoggedRequest in project RoboZombie by sahan.

the class HttpMethodEndpointTest method testPostMethod.

/**
	 * <p>Test for the request method POST.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testPostMethod() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String path = "/postrequest";
    stubFor(post(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
    String name = "DoctorWho", age = "953", location = "Tardis";
    httpMethodEndpoint.postRequest(name, age, location);
    List<LoggedRequest> requests = findAll(postRequestedFor(urlMatching(path)));
    assertFalse(requests == null);
    assertFalse(requests.isEmpty());
    LoggedRequest request = requests.get(0);
    assertTrue(request.getMethod().equals(RequestMethod.POST));
    String body = request.getBodyAsString();
    assertTrue(body.contains("name=" + name));
    assertTrue(body.contains("age=" + age));
    assertTrue(body.contains("location=" + location));
}
Also used : LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Test(org.junit.Test)

Example 2 with LoggedRequest

use of com.github.tomakehurst.wiremock.verification.LoggedRequest in project RoboZombie by sahan.

the class HttpMethodEndpointTest method testGetMethod.

/**
	 * <p>Test for the request method GET.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testGetMethod() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String name = "James-Howlett", age = "116", location = "X-Mansion";
    String path = "/getrequest?name=" + name + "&age=" + age + "&location=" + location;
    stubFor(get(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
    httpMethodEndpoint.getRequest(name, age, location);
    List<LoggedRequest> requests = findAll(getRequestedFor(urlEqualTo(path)));
    assertFalse(requests == null);
    assertFalse(requests.isEmpty());
    LoggedRequest request = requests.get(0);
    assertTrue(request.getMethod().equals(RequestMethod.GET));
}
Also used : LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Test(org.junit.Test)

Example 3 with LoggedRequest

use of com.github.tomakehurst.wiremock.verification.LoggedRequest in project RoboZombie by sahan.

the class HttpMethodEndpointTest method testPutMethod.

/**
	 * <p>Test for the request method PUT.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testPutMethod() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String path = "/putrequest";
    stubFor(put(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
    String user = "{ '_id':1, 'alias':'Black Bolt' }";
    httpMethodEndpoint.putRequest(user);
    List<LoggedRequest> requests = findAll(putRequestedFor(urlMatching(path)));
    assertFalse(requests == null);
    assertFalse(requests.isEmpty());
    LoggedRequest request = requests.get(0);
    assertTrue(request.getMethod().equals(RequestMethod.PUT));
    String body = request.getBodyAsString();
    assertTrue(body.contains(user));
}
Also used : LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Test(org.junit.Test)

Aggregations

LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)3 Test (org.junit.Test)3