Package com.github.tomakehurst.wiremock.http

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


  @Override
  protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    LocalNotifier.set(notifier);
   
    Request request = new Jetty6HttpServletRequestAdapter(httpServletRequest, mappedUnder);
        notifier.info("Received request: " + httpServletRequest.toString());

    Response response = requestHandler.handle(request);
    if (response.wasConfigured()) {
        applyResponse(response, httpServletResponse);
    } else if (request.getMethod() == GET && shouldForwardToFilesContext) {
        forwardToFilesContext(httpServletRequest, httpServletResponse, request);
    } else {
      httpServletResponse.sendError(HTTP_NOT_FOUND);
    }
  }
View Full Code Here


  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

  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

  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

    assertThat(response.getStatus(), is(HTTP_NOT_FOUND));
  }
 
  @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

    secondGetMapping.setScenarioName("TestScenario");
    secondGetMapping.setRequiredScenarioState("Modified");
    mappings.addMapping(secondGetMapping);
   
   
    Request firstGet = aRequest(context, "firstGet").withMethod(GET).withUrl("/scenario/resource").build();
    Request put = aRequest(context, "put").withMethod(PUT).withUrl("/scenario/resource").build();
    Request secondGet = aRequest(context, "secondGet").withMethod(GET).withUrl("/scenario/resource").build();
   
    assertThat(mappings.serveFor(firstGet).getBody(), is("Initial content"));
    mappings.serveFor(put);
    assertThat(mappings.serveFor(secondGet).getBody(), is("Modified content"));
  }
View Full Code Here

        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();
   
    assertThat(mappings.serveFor(request).getBody(), is("Expected content"));
  }
View Full Code Here

        StubMapping secondMapping = aBasicMappingInScenario("Modified content");
        secondMapping.setRequiredScenarioState("modified");
        mappings.addMapping(secondMapping);

        Request request = aRequest(context).withMethod(POST).withUrl("/scenario/resource").build();
        mappings.serveFor(request);
        assertThat(mappings.serveFor(request).getBody(), is("Modified content"));

        mappings.reset();
View Full Code Here

  }
 
  @Test
  public void matchesOnExactMethodAndUrl() {
    RequestPattern requestPattern = new RequestPattern(RequestMethod.POST, "/some/resource/path");
    Request request = aRequest(context)
      .withUrl("/some/resource/path")
      .withMethod(POST)
      .build();
    assertTrue(requestPattern.isMatchedBy(request));
  }
View Full Code Here

  }
 
  @Test
  public void shouldNotMatchWhenMethodIsCorrectButUrlIsWrong() {
    RequestPattern requestPattern = new RequestPattern(RequestMethod.POST, "/some/resource/path");
    Request request = aRequest(context)
      .withUrl("/wrong/path")
      .withMethod(POST)
      .build();
    assertFalse(requestPattern.isMatchedBy(request));
  }
View Full Code Here

TOP

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

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.