Example #1
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithMultipleQueryParams()
      throws Exception {

    final String expectedParamOne = "paramOne";
    final String expectedParamOneValue = "one";
    final String fullQueryOne = String.format("%s=%s", expectedParamOne, expectedParamOneValue);

    final String expectedParamTwo = "paramTwo";
    final String expectedParamTwoValue = "two";
    final String fullQueryTwo = String.format("%s=%s", expectedParamTwo, expectedParamTwoValue);

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .withUrl("/some/uri")
            .withQuery(expectedParamOne, expectedParamOneValue)
            .withQuery(expectedParamTwo, expectedParamTwoValue)
            .newStubbedResponse()
            .withStatus("500")
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
    final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
    final StubRequest actualRequest = actualHttpLifecycle.getRequest();
    final MapEntry queryEntryOne = MapEntry.entry(expectedParamOne, expectedParamOneValue);
    final MapEntry queryEntryTwo = MapEntry.entry(expectedParamTwo, expectedParamTwoValue);

    assertThat(actualRequest.getUrl()).contains(fullQueryOne);
    assertThat(actualRequest.getUrl()).contains(fullQueryTwo);
    assertThat(actualRequest.getQuery()).contains(queryEntryOne, queryEntryTwo);
  }
Example #2
0
  @Test
  public void
      shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WitQueryParamIsArrayHavingSingleQuotes()
          throws Exception {

    final String expectedParamOne = "fruits";
    final String expectedParamOneValue = "['apple','orange','banana']";
    final String fullQueryOne = String.format("%s=%s", expectedParamOne, expectedParamOneValue);

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .withUrl("/some/uri")
            .withQuery(expectedParamOne, String.format("\"%s\"", expectedParamOneValue))
            .newStubbedResponse()
            .withStatus("201")
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
    final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
    final StubRequest actualRequest = actualHttpLifecycle.getRequest();
    final MapEntry queryEntryOne = MapEntry.entry(expectedParamOne, expectedParamOneValue);

    assertThat(actualRequest.getUrl()).contains(fullQueryOne);
    assertThat(actualRequest.getQuery()).contains(queryEntryOne);
  }
Example #3
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithUrlAsRegex() throws Exception {

    final String url = "^/[a-z]{3}/[0-9]+/?$";
    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .withUrl(url)
            .newStubbedResponse()
            .withStatus("301")
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
    final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
    final StubRequest actualRequest = actualHttpLifecycle.getRequest();

    assertThat(actualRequest.getUrl()).isEqualTo(url);
  }