Examples of ResponseDefinition


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

    this.fault = fault;
    return this;
  }
 
  public ResponseDefinition build() {
        ResponseDefinition response;

        if(isBinaryBody) {
          response = new ResponseDefinition(status, bodyContent);
        } else {
            if(bodyContent==null) {
                response = new ResponseDefinition(status, (String)null);
            } else {
                response = new ResponseDefinition(status, new String(bodyContent,Charset.forName(UTF_8.name())));
            }
        }

        if (!headers.isEmpty()) {
            response.setHeaders(new HttpHeaders(headers));
        }
   
        response.setBodyFileName(bodyFileName);
    response.setFixedDelayMilliseconds(fixedDelayMilliseconds);
    response.setProxyBaseUrl(proxyBaseUrl);
    response.setFault(fault);
    return response;
  }
View Full Code Here

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

  public StubMapping build() {
    if (scenarioName == null && (requiredScenarioState != null || newScenarioState != null)) {
      throw new IllegalStateException("Scenario name must be specified to require or set a new scenario state");
    }
    RequestPattern requestPattern = requestPatternBuilder.build();
    ResponseDefinition response = responseDefBuilder.build();
    StubMapping mapping = new StubMapping(requestPattern, response);
    mapping.setPriority(priority);
    mapping.setScenarioName(scenarioName);
    mapping.setRequiredScenarioState(requiredScenarioState);
    mapping.setNewScenarioState(newScenarioState);
View Full Code Here

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

 
  @Test
  public void correctlyAcceptsMappingAndReturnsCorrespondingResponse() {
    mappings.addMapping(new StubMapping(
        new RequestPattern(PUT, "/some/resource"),
        new ResponseDefinition(204, "")));
   
    Request request = aRequest(context).withMethod(PUT).withUrl("/some/resource").build();
    ResponseDefinition response = mappings.serveFor(request);
   
    assertThat(response.getStatus(), is(204));
  }
View Full Code Here

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

 
  @Test
  public void returnsNotFoundWhenMethodIncorrect() {
    mappings.addMapping(new StubMapping(
        new RequestPattern(PUT, "/some/resource"),
        new ResponseDefinition(204, "")));
   
    Request request = aRequest(context).withMethod(POST).withUrl("/some/resource").build();
    ResponseDefinition response = mappings.serveFor(request);
   
    assertThat(response.getStatus(), is(HTTP_NOT_FOUND));
  }
View Full Code Here

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

 
  @Test
  public void returnsNotFoundWhenUrlIncorrect() {
    mappings.addMapping(new StubMapping(
        new RequestPattern(PUT, "/some/resource"),
        new ResponseDefinition(204, "")));
   
    Request request = aRequest(context).withMethod(PUT).withUrl("/some/bad/resource").build();
    ResponseDefinition response = mappings.serveFor(request);
   
    assertThat(response.getStatus(), is(HTTP_NOT_FOUND));
  }
View Full Code Here

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

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

 
  @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

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

 
  @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

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

 
  @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

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

 
  @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
TOP
Copyright © 2018 www.massapi.com. 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.