예제 #1
0
 protected void skipIfMethodNotAllowed(HttpMethod method) {
   if (!supports(method)) {
     throw new SkipMethodNotAllowedException(
         Thread.currentThread().getStackTrace()[1].getMethodName(),
         getResourceUri(),
         method,
         skipLog);
   }
 }
예제 #2
0
 @Test(
     groups = {MUST, MANUAL},
     description = "LDP servers MUST at least be" + " HTTP/1.1 conformant servers [HTTP11].")
 @SpecTest(
     specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-gen-http",
     testMethod = METHOD.MANUAL,
     approval = STATUS.WG_APPROVED,
     comment =
         "Covers only part of the specification requirement. "
             + "testIsHttp11Server covers the rest.")
 public void testIsHttp11Manual() throws URISyntaxException {
   throw new SkipNotTestableException(
       Thread.currentThread().getStackTrace()[1].getMethodName(), skipLog);
 }
예제 #3
0
  @Test(
      groups = {MUST},
      description =
          "LDP servers MUST respond with status code 412 "
              + "(Condition Failed) if ETags fail to match when there "
              + "are no other errors with the request [HTTP11]. LDP "
              + "servers that require conditional requests MUST respond "
              + "with status code 428 (Precondition Required) when the "
              + "absence of a precondition is the only reason for rejecting "
              + "the request [RFC6585].")
  @SpecTest(
      specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond",
      testMethod = METHOD.AUTOMATED,
      approval = STATUS.WG_APPROVED,
      comment =
          "Covers only part of the specification requirement. "
              + "testConditionFailedStatusCode,  testPutBadETag"
              + "and testPutRequiresIfMatch covers the rest.")
  public void testPreconditionRequiredStatusCode() {
    skipIfMethodNotAllowed(HttpMethod.PUT);

    String resourceUri = getResourceUri();
    Response getResponse =
        buildBaseRequestSpecification()
            .expect()
            .statusCode(isSuccessful())
            .header(ETAG, isValidEntityTag())
            .when()
            .get(resourceUri);

    // Verify that we can successfully PUT the resource WITH an If-Match header.
    Response ifMatchResponse =
        buildBaseRequestSpecification()
            .header(IF_MATCH, getResponse.getHeader(ETAG))
            .contentType(getResponse.contentType())
            .body(getResponse.asByteArray())
            .when()
            .put(resourceUri);
    if (!isSuccessful().matches(ifMatchResponse.getStatusCode())) {
      throw new SkipException(
          Thread.currentThread().getStackTrace()[1].getMethodName(),
          "Skipping test because PUT request failed with valid If-Match header.",
          skipLog);
    }

    // Now try WITHOUT the If-Match header. If the result is NOT successful,
    // it should be because the header is missing and we can check the error
    // code.
    Response noIfMatchResponse =
        buildBaseRequestSpecification()
            .contentType(getResponse.contentType())
            .body(getResponse.asByteArray())
            .when()
            .put(resourceUri);
    if (isSuccessful().matches(noIfMatchResponse.getStatusCode())) {
      // It worked. This server doesn't require If-Match, which is only a
      // SHOULD requirement (see testPutRequiresIfMatch). Skip the test.
      throw new SkipException(
          Thread.currentThread().getStackTrace()[1].getMethodName(),
          "Server does not require If-Match header.",
          skipLog);
    }

    assertEquals(
        428,
        noIfMatchResponse.getStatusCode(),
        "Expected 428 Precondition Required error on PUT request with no If-Match header");
  }