コード例 #1
0
  @Test
  public void shouldLogMessageIndicatingFailedHeaderMatch() {
    context.checking(
        new Expectations() {
          {
            one(notifier)
                .info(
                    "URL /for/logging is match, but header Content-Type is not. For a match, value should equal text/xml");
          }
        });

    RequestPattern requestPattern = new RequestPattern(POST, "/for/logging");
    ValuePattern headerPattern = new ValuePattern();
    headerPattern.setEqualTo("text/xml");
    requestPattern.addHeader("Content-Type", headerPattern);

    Request request =
        aRequest(context)
            .withUrl("/for/logging")
            .withMethod(POST)
            .withHeader("Content-Type", "text/plain")
            .build();

    requestPattern.isMatchedBy(request);
  }
コード例 #2
0
  @Test
  public void shouldMatchOnBodyPattern() {
    RequestPattern requestPattern = new RequestPattern(GET, "/with/body");
    requestPattern.setBodyPatterns(
        asList(ValuePattern.matches(".*<important>Value</important>.*")));

    Request request =
        aRequest(context).withUrl("/with/body").withMethod(GET).withBody(XML_SAMPLE).build();

    assertTrue(requestPattern.isMatchedBy(request));
  }
コード例 #3
0
  @Test
  public void supportsMatchingOnAbsentHeader() {
    ignoringNotifier();

    RequestPattern requestPattern = new RequestPattern(GET, "/without/header");
    requestPattern.addHeader("X-My-Header", ValuePattern.absent());
    Request request =
        aRequest(context)
            .withUrl("/without/header")
            .withMethod(GET)
            .withHeader("X-Another-Header", "value")
            .build();

    assertTrue(
        "Request is not a match for the request pattern", requestPattern.isMatchedBy(request));
  }
コード例 #4
0
  @Test
  public void shouldFailMatchWhenRequiredAbsentHeaderIsPresent() {
    ignoringNotifier();

    RequestPattern requestPattern = new RequestPattern(GET, "/without/header/fail");
    requestPattern.addHeader("X-My-Header", ValuePattern.absent());
    Request request =
        aRequest(context)
            .withUrl("/without/header/fail")
            .withMethod(GET)
            .withHeader("X-My-Header", "value")
            .build();

    assertFalse(
        "Request is a match for the request pattern and should not be",
        requestPattern.isMatchedBy(request));
  }
コード例 #5
0
  @Test
  public void shouldNotMatchWhenBodyDoesNotMatchPattern() {
    ignoringNotifier();

    RequestPattern requestPattern = new RequestPattern(GET, "/with/body");
    requestPattern.setBodyPatterns(
        asList(ValuePattern.matches(".*<important>Value</important>.*")));

    Request request =
        aRequest(context)
            .withUrl("/with/body")
            .withMethod(GET)
            .withBody("<important>Wrong value</important>")
            .build();

    assertFalse(requestPattern.isMatchedBy(request));
  }
コード例 #6
0
  @Test
  public void shouldLogMessageIndicatingFailedBodyMatch() {
    context.checking(
        new Expectations() {
          {
            one(notifier).info("URL /for/logging is match, but body is not: Actual Content");
          }
        });

    RequestPattern requestPattern = new RequestPattern(POST, "/for/logging");
    requestPattern.setBodyPatterns(asList(ValuePattern.matches("Expected content")));

    Request request =
        aRequest(context)
            .withUrl("/for/logging")
            .withMethod(POST)
            .withBody("Actual Content")
            .build();

    requestPattern.isMatchedBy(request);
  }
コード例 #7
0
 private ValuePattern parameterDoesNotMatch(String value) {
   ValuePattern parameterPattern = new ValuePattern();
   parameterPattern.setDoesNotMatch(value);
   return parameterPattern;
 }
コード例 #8
0
 private ValuePattern parameterMatches(String value) {
   ValuePattern parameterPattern = new ValuePattern();
   parameterPattern.setMatches(value);
   return parameterPattern;
 }
コード例 #9
0
 private ValuePattern parameterEqualTo(String value) {
   ValuePattern parameterPattern = new ValuePattern();
   parameterPattern.setEqualTo(value);
   return parameterPattern;
 }
コード例 #10
0
 private ValuePattern headerDoesNotMatch(String value) {
   ValuePattern headerPattern = new ValuePattern();
   headerPattern.setDoesNotMatch(value);
   return headerPattern;
 }
コード例 #11
0
 private ValuePattern headerMatches(String value) {
   ValuePattern headerPattern = new ValuePattern();
   headerPattern.setMatches(value);
   return headerPattern;
 }
コード例 #12
0
 private ValuePattern headerEqualTo(String value) {
   ValuePattern headerPattern = new ValuePattern();
   headerPattern.setEqualTo(value);
   return headerPattern;
 }