Examples of StubMapping


Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

        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

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

public class NewStubMappingTask implements AdminTask {

    @Override
    public ResponseDefinition execute(Admin admin, Request request) {
        StubMapping newMapping = StubMapping.buildFrom(request.getBodyAsString());
        admin.addStubMapping(newMapping);
        return ResponseDefinition.created();
    }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

  @Test
  public void shouldBuildMappingWithExactUrlNoHeaders() {
    UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy();
    urlStrategy.setUrl("/match/this");
    StubMapping mapping =
      new MappingBuilder(POST, urlStrategy)
      .willReturn(new ResponseDefinitionBuilder().withStatus(201))
      .build();
   
    assertThat(mapping.getRequest().getUrl(), is("/match/this"));
    assertThat(mapping.getRequest().getMethod(), is(POST));
    assertThat(mapping.getResponse().getStatus(), is(201));
  }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

 
  @Test
  public void shouldBuildMappingWithMatchedUrlNoHeaders() {
    UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy();
    urlStrategy.setUrlPattern("/match/[A-Z]{5}");
    StubMapping mapping =
      new MappingBuilder(POST, urlStrategy)
      .willReturn(new ResponseDefinitionBuilder())
      .build();
   
    assertThat(mapping.getRequest().getUrlPattern(), is("/match/[A-Z]{5}"));
  }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

  @Test
  public void shouldBuildMappingWithExactUrlAndRequestHeaders() {
    UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy();
    urlStrategy.setUrl("/match/this");
   
    StubMapping mapping =
      new MappingBuilder(POST, urlStrategy)
      .withHeader("Content-Type", headerStrategyEqualTo("text/plain"))
      .withHeader("Encoding", headerStrategyMatches("UTF-\\d"))
      .withHeader("X-My-Thing", headerStrategyDoesNotMatch("[A-Z]+"))
      .willReturn(new ResponseDefinitionBuilder())
      .build();
   
    assertThat(mapping.getRequest().getHeaders(), hasEntry("Content-Type", headerEqualTo("text/plain")));
    assertThat(mapping.getRequest().getHeaders(), hasEntry("Encoding", headerMatches("UTF-\\d")));
    assertThat(mapping.getRequest().getHeaders(), hasEntry("X-My-Thing", headerDoesNotMatch("[A-Z]+")));
  }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

    assertThat(mapping.getRequest().getHeaders(), hasEntry("X-My-Thing", headerDoesNotMatch("[A-Z]+")));
  }
 
  @Test
  public void shouldBuildMappingWithResponseBody() {
    StubMapping mapping =
      new MappingBuilder(POST, new UrlMatchingStrategy())
      .willReturn(new ResponseDefinitionBuilder().withBody("Some content"))
      .build();
   
    assertThat(mapping.getResponse().getBody(), is("Some content"));
  }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

    assertThat(mapping.getResponse().getBody(), is("Some content"));
  }

    @Test
    public void shouldBuildMappingWithResponseByteBody() {
        StubMapping mapping =
                new MappingBuilder(POST, new UrlMatchingStrategy())
                        .willReturn(new ResponseDefinitionBuilder().withBody("Some content".getBytes()))
                        .build();

        assertThat(mapping.getResponse().getByteBody(), is("Some content".getBytes()));
    }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

    }

    @SuppressWarnings("unchecked")
  @Test
  public void shouldBuildMappingWithResponseHeaders() {
    StubMapping mapping =
      new MappingBuilder(POST, new UrlMatchingStrategy())
      .willReturn(new ResponseDefinitionBuilder()
        .withHeader("Content-Type", "text/xml")
        .withHeader("Encoding", "UTF-8"))
      .build();
   
    assertThat(mapping.getResponse().getHeaders().all(), hasItems(
                header("Content-Type", "text/xml"),
                header("Encoding", "UTF-8")));
  }
View Full Code Here

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

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

Examples of com.github.tomakehurst.wiremock.stubbing.StubMapping

  }

    @Test
    public void shouldRegisterStubMapping() {
        expectExactlyOneAddResponseCallWithJson(MappingJsonSamples.WITH_RESPONSE_BODY);
        StubMapping mapping = StubMapping.buildFrom(MappingJsonSamples.SPEC_WITH_RESPONSE_BODY);

        wireMock.register(mapping);
    }
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.