Esempio n. 1
0
  @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));
  }
Esempio n. 2
0
  @Test
  public void shouldBuildMappingWithExactUrlAndRequestParameters() {
    UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy();
    urlStrategy.setUrl("/match/this");

    StubMapping mapping =
        new MappingBuilder(POST, urlStrategy)
            .withParameter("p1", parameterStrategyEqualTo("val1"))
            .withParameter("p2", parameterStrategyMatches("val\\d"))
            .withParameter("p3", parameterStrategyDoesNotMatch("[A-Z]+"))
            .willReturn(new ResponseDefinitionBuilder())
            .build();

    assertThat(mapping.getRequest().getParameters(), hasEntry("p1", parameterEqualTo("val1")));
    assertThat(mapping.getRequest().getParameters(), hasEntry("p2", parameterMatches("val\\d")));
    assertThat(
        mapping.getRequest().getParameters(), hasEntry("p3", parameterDoesNotMatch("[A-Z]+")));
  }
Esempio n. 3
0
  @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]+")));
  }