Package com.github.tomakehurst.wiremock.http

Examples of com.github.tomakehurst.wiremock.http.ResponseDefinition


  }
 
  @Test
  public void returnsNotConfiguredResponseForUnmappedRequest() {
    Request request = aRequest(context).withMethod(OPTIONS).withUrl("/not/mapped").build();
    ResponseDefinition response = mappings.serveFor(request);
    assertThat(response.getStatus(), is(HTTP_NOT_FOUND));
    assertThat(response.wasConfigured(), is(false));
  }
View Full Code Here


 
  @Test
  public void returnsMostRecentlyInsertedResponseIfTwoOrMoreMatch() {
    mappings.addMapping(new StubMapping(
        new RequestPattern(GET, "/duplicated/resource"),
        new ResponseDefinition(204, "Some content")));
   
    mappings.addMapping(new StubMapping(
        new RequestPattern(GET, "/duplicated/resource"),
        new ResponseDefinition(201, "Desired content")));
   
    ResponseDefinition response = mappings.serveFor(aRequest(context).withMethod(GET).withUrl("/duplicated/resource").build());
   
    assertThat(response.getStatus(), is(201));
    assertThat(response.getBody(), is("Desired content"));
  }
View Full Code Here

 
  @Test
  public void returnsMappingInScenarioOnlyWhenStateIsCorrect() {
    StubMapping firstGetMapping = new StubMapping(
        new RequestPattern(GET, "/scenario/resource"),
        new ResponseDefinition(204, "Initial content"));
    firstGetMapping.setScenarioName("TestScenario");
    firstGetMapping.setRequiredScenarioState(STARTED);
    mappings.addMapping(firstGetMapping);
   
    StubMapping putMapping = new StubMapping(
        new RequestPattern(PUT, "/scenario/resource"),
        new ResponseDefinition(204, ""));
    putMapping.setScenarioName("TestScenario");
    putMapping.setRequiredScenarioState(STARTED);
    putMapping.setNewScenarioState("Modified");
    mappings.addMapping(putMapping);
   
    StubMapping secondGetMapping = new StubMapping(
        new RequestPattern(GET, "/scenario/resource"),
        new ResponseDefinition(204, "Modified content"));
    secondGetMapping.setScenarioName("TestScenario");
    secondGetMapping.setRequiredScenarioState("Modified");
    mappings.addMapping(secondGetMapping);
   
   
View Full Code Here

 
  @Test
  public void returnsMappingInScenarioWithNoRequiredState() {
    StubMapping firstGetMapping = new StubMapping(
        new RequestPattern(GET, "/scenario/resource"),
        new ResponseDefinition(200, "Expected content"));
    firstGetMapping.setScenarioName("TestScenario");
    mappings.addMapping(firstGetMapping);
   
    Request request = aRequest(context).withMethod(GET).withUrl("/scenario/resource").build();
   
View Full Code Here

 
  @Test
  public void supportsResetOfAllScenariosState() {
    StubMapping firstGetMapping = new StubMapping(
        new RequestPattern(GET, "/scenario/resource"),
        new ResponseDefinition(204, "Desired content"));
    firstGetMapping.setScenarioName("TestScenario");
    firstGetMapping.setRequiredScenarioState(STARTED);
    mappings.addMapping(firstGetMapping);
   
    StubMapping putMapping = new StubMapping(
        new RequestPattern(PUT, "/scenario/resource"),
        new ResponseDefinition(204, ""));
    putMapping.setScenarioName("TestScenario");
    putMapping.setRequiredScenarioState(STARTED);
    putMapping.setNewScenarioState("Modified");
    mappings.addMapping(putMapping);
   
    mappings.serveFor(
        aRequest(context, "put /scenario/resource")
        .withMethod(PUT).withUrl("/scenario/resource").build());
    ResponseDefinition response =
      mappings.serveFor(
          aRequest(context, "1st get /scenario/resource")
          .withMethod(GET).withUrl("/scenario/resource").build());
   
    assertThat(response.wasConfigured(), is(false));
   
    mappings.resetScenarios();
    response =
      mappings.serveFor(
          aRequest(context, "2nd get /scenario/resource")
          .withMethod(GET).withUrl("/scenario/resource").build());
    assertThat(response.getBody(), is("Desired content"));
  }
View Full Code Here

    }

    private StubMapping aBasicMappingInScenario(String body) {
        StubMapping mapping = new StubMapping(
                new RequestPattern(POST, "/scenario/resource"),
                new ResponseDefinition(200, body));
        mapping.setScenarioName("TestScenario");
        return mapping;
    }
View Full Code Here

    return this;
  }
 
  public StubMapping build() {
    RequestPattern requestPattern = new RequestPattern(method, url);
    ResponseDefinition response = new ResponseDefinition(responseStatus, responseBody);
    response.setHeaders(new HttpHeaders(headers));
    StubMapping mapping = new StubMapping(requestPattern, response);
    return mapping;
  }
View Full Code Here

public class ResponseDefinitionTest {

    @Test
    public void copyProducesEqualObject() {
        ResponseDefinition response = new ResponseDefinition();
        response.setBody("blah");
        response.setBodyFileName("name.json");
        response.setFault(Fault.EMPTY_RESPONSE);
        response.setHeaders(new HttpHeaders(httpHeader("thing", "thingvalue")));
        response.setFixedDelayMilliseconds(1112);
        response.setProxyBaseUrl("http://base.com");
        response.setStatus(222);
       
        ResponseDefinition copiedResponse = copyOf(response);
       
        assertTrue(response.equals(copiedResponse));
    }
View Full Code Here

        assertTrue(response.equals(copiedResponse));
    }
   
    @Test
    public void copyPreservesConfiguredFlag() {
        ResponseDefinition response = ResponseDefinition.notConfigured();
        ResponseDefinition copiedResponse = copyOf(response);
        assertFalse("Should be not configured", copiedResponse.wasConfigured());
    }
View Full Code Here

            "    \"body\": \"String content\"     \n" +
            "}                      ";

    @Test
    public void correctlyUnmarshalsFromJsonWhenBodyIsAString() {
        ResponseDefinition responseDef = Json.read(STRING_BODY, ResponseDefinition.class);
        assertThat(responseDef.getBase64Body(), is(nullValue()));
        assertThat(responseDef.getBody(), is("String content"));
    }
View Full Code Here

TOP

Related Classes of com.github.tomakehurst.wiremock.http.ResponseDefinition

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.