Exemplo n.º 1
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithOneSequenceResponse()
      throws Exception {

    final String sequenceResponseHeaderKey = "content-type";
    final String sequenceResponseHeaderValue = "application/json";
    final String sequenceResponseStatus = "200";
    final String sequenceResponseBody = "OK";

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodPut()
            .withUrl("/invoice")
            .newStubbedResponse()
            .withSequenceResponseStatus(sequenceResponseStatus)
            .withSequenceResponseHeaders(sequenceResponseHeaderKey, sequenceResponseHeaderValue)
            .withSequenceResponseLiteralBody(sequenceResponseBody)
            .build();

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

    final MapEntry sequenceHeaderEntry =
        MapEntry.entry(sequenceResponseHeaderKey, sequenceResponseHeaderValue);

    assertThat(actualResponse).isInstanceOf(StubResponse.class);
    assertThat(actualResponse.getHeaders()).contains(sequenceHeaderEntry);
    assertThat(actualResponse.getStatus()).isEqualTo(sequenceResponseStatus);
    assertThat(actualResponse.getBody()).isEqualTo(sequenceResponseBody);
  }
Exemplo n.º 2
0
  @Test
  public void shouldUnmarshallYamlIntoObjectTree_WhenYAMLValid_WithDefaultHTTPResponseStatus()
      throws Exception {

    final String yaml =
        YAML_BUILDER
            .newStubbedRequest()
            .withMethodGet()
            .newStubbedResponse()
            .withLiteralBody("hello")
            .build();

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

    assertThat(actualResponse.getStatus()).isEqualTo(String.valueOf(200));
  }
Exemplo n.º 3
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);
  }