Package com.github.tomakehurst.wiremock.http

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


    @Override
    public ResponseDefinition execute(Admin admin, Request request) {
        RequestPattern requestPattern = buildRequestPatternFrom(request.getBodyAsString());
        FindRequestsResult result = admin.findRequestsMatching(requestPattern);
        ResponseDefinition response = new ResponseDefinition(HTTP_OK, Json.write(result));
        response.setHeaders(new HttpHeaders(httpHeader("Content-Type", "application/json")));
        return response;
    }
View Full Code Here


    @Override
    public ResponseDefinition execute(Admin admin, Request request) {
        RequestPattern requestPattern = buildRequestPatternFrom(request.getBodyAsString());
        VerificationResult result = admin.countRequestsMatching(requestPattern);
        ResponseDefinition response = new ResponseDefinition(HTTP_OK, write(result));
        response.setHeaders(new HttpHeaders(httpHeader("Content-Type", "application/json")));
        return response;
    }
View Full Code Here

    wireMockServer.loadMappingsUsing(new MappingsLoader() {
      @Override
      public void loadMappingsInto(StubMappings stubMappings) {
        RequestPattern requestPattern = new RequestPattern(ANY);
        requestPattern.setUrlPattern(".*");
        ResponseDefinition responseDef = new ResponseDefinition();
        responseDef.setProxyBaseUrl(baseUrl);

        StubMapping proxyBasedMapping = new StubMapping(requestPattern, responseDef);
        proxyBasedMapping.setPriority(10); // Make it low priority so that existing stubs will take precedence
        stubMappings.addMapping(proxyBasedMapping);
      }
View Full Code Here

    public void returnsOkResponse() {
        context.checking(new Expectations() {{
            oneOf(mockAdmin).saveMappings();
        }});

        ResponseDefinition response = saveMappingsTask.execute(mockAdmin, mockRequest);

        assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    }
View Full Code Here

    assertThat("Mapping set should be empty", mappingSet.iterator().hasNext(), is(false));
  }
 
  private StubMapping aMapping(Integer priority, String url) {
    RequestPattern requestPattern = new RequestPattern(ANY, url);
    StubMapping mapping = new StubMapping(requestPattern, new ResponseDefinition());
    mapping.setPriority(priority);
    return mapping;
  }
View Full Code Here

    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

  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

 
  @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

 
  @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

 
  @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

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.