Package com.github.tomakehurst.wiremock.matching

Examples of com.github.tomakehurst.wiremock.matching.RequestPattern


  }
 
  @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);
   
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));
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);
View Full Code Here

        assertThat(mappings.serveFor(request).getBody(), is("Starting content"));
    }

    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

      LocalNotifier.set(null);
  }
 
  @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

    assertTrue(requestPattern.isMatchedBy(request));
  }
 
  @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

 
  @Test
  public void shouldMatchWhenSpecifiedHeadersArePresent() {
    headerPatterns.put("Accept", equalTo("text/plain"));
    headerPatterns.put("Content-Type", equalTo("application/json"));
    RequestPattern requestPattern = new RequestPattern(RequestMethod.GET, "/header/dependent/resource", headerPatterns);
   
    Request request = aRequest(context)
      .withUrl("/header/dependent/resource")
      .withMethod(GET)
      .withHeader("Accept", "text/plain")
      .withHeader("Content-Type", "application/json")
      .build();
   
    assertTrue(requestPattern.isMatchedBy(request));
  }
View Full Code Here

  public void shouldNotMatchWhenASpecifiedHeaderIsAbsent() {
      ignoringNotifier();
     
    headerPatterns.put("Accept", equalTo("text/plain"));
    headerPatterns.put("Content-Type", equalTo("application/json"));
    RequestPattern requestPattern = new RequestPattern(RequestMethod.GET, "/header/dependent/resource", headerPatterns);
   
    Request request = aRequest(context)
      .withUrl("/header/dependent/resource")
      .withMethod(GET)
      .withHeader("Accept", "text/plain")
      .build();
   
    assertFalse(requestPattern.isMatchedBy(request));
  }
View Full Code Here

TOP

Related Classes of com.github.tomakehurst.wiremock.matching.RequestPattern

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.