コード例 #1
0
  @Test
  public void shouldContainTheSameResourceIdHeader_ForEachSequencedResponse() throws Exception {

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodPut()
            .withUrl("/invoice")
            .newStubbedResponse()
            .withSequenceResponseStatus("200")
            .withSequenceResponseHeaders("headerOne", "valueOne")
            .withSequenceResponseLiteralBody("BodyContent")
            .withSequenceResponseStatus("200")
            .withSequenceResponseHeaders("headerTwo", "valueTwo")
            .withSequenceResponseLiteralBody("BodyContentTwo")
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
    assertThat(loadedHttpCycles.size()).isEqualTo(1);

    final StubHttpLifecycle cycle = loadedHttpCycles.get(0);
    final List<StubResponse> allResponses = cycle.getAllResponses();

    for (int idx = 0; idx < allResponses.size(); idx++) {
      final StubResponse sequenceStubResponse = allResponses.get(idx);
      assertThat(sequenceStubResponse.getHeaders())
          .containsKey(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      assertThat(sequenceStubResponse.getHeaders().get(StubResponse.STUBBY_RESOURCE_ID_HEADER))
          .isEqualTo(String.valueOf(0));
    }
  }
コード例 #2
0
  @Test
  public void
      shouldContainExpectedResourceIdHeaderUponSuccessfulYamlMarshall_WhenMultipleAndSqequencedResponses()
          throws Exception {

    final String cycleOne =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .withUrl("/some/uri/1")
            .withQuery("paramName1", "paramValue1")
            .newStubbedResponse()
            .withStatus("200")
            .build();

    final String cycleTwo =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodPut()
            .withUrl("/invoice")
            .newStubbedResponse()
            .withSequenceResponseStatus("200")
            .withSequenceResponseHeaders("headerOne", "valueOne")
            .withSequenceResponseLiteralBody("BodyContent")
            .withSequenceResponseStatus("200")
            .withSequenceResponseHeaders("headerTwo", "valueTwo")
            .withSequenceResponseLiteralBody("BodyContentTwo")
            .build();

    final String cycleThree =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .withUrl("/some/uri/2")
            .withQuery("paramName2", "paramValue2")
            .newStubbedResponse()
            .withStatus("201")
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles =
        unmarshall(String.format("%s%s%s%s%s", cycleOne, BR, cycleTwo, BR, cycleThree));
    assertThat(loadedHttpCycles.size()).isEqualTo(3);

    for (int resourceId = 0; resourceId < loadedHttpCycles.size(); resourceId++) {
      final StubHttpLifecycle cycle = loadedHttpCycles.get(resourceId);
      final List<StubResponse> allResponses = cycle.getAllResponses();

      for (int sequence = 0; sequence < allResponses.size(); sequence++) {
        final StubResponse sequenceStubResponse = allResponses.get(sequence);
        assertThat(sequenceStubResponse.getHeaders())
            .containsKey(StubResponse.STUBBY_RESOURCE_ID_HEADER);
        assertThat(sequenceStubResponse.getHeaders().get(StubResponse.STUBBY_RESOURCE_ID_HEADER))
            .isEqualTo(String.valueOf(resourceId));
      }
    }
  }
コード例 #3
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithNoProperties() throws Exception {

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodPut()
            .withUrl("/invoice")
            .newStubbedResponse()
            .build();

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

    assertThat(actualHttpLifecycle.getAllResponses()).hasSize(1);
  }
コード例 #4
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithNoSequenceResponses()
      throws Exception {

    final String expectedStatus = "301";
    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodPut()
            .withUrl("/invoice")
            .newStubbedResponse()
            .withStatus(expectedStatus)
            .build();

    final List<StubHttpLifecycle> loadedHttpCycles = unmarshall(yaml);
    final StubHttpLifecycle actualHttpLifecycle = loadedHttpCycles.get(0);
    final StubResponse actualResponse = actualHttpLifecycle.getResponse(true);

    assertThat(actualHttpLifecycle.getAllResponses()).hasSize(1);
    assertThat(actualResponse.getStatus()).isEqualTo(expectedStatus);
  }