コード例 #1
0
  public void testCors() {
    Response response = given().options("/rest/questionnaire/some-permalink");

    assertThat(response.getStatusCode()).isEqualTo(Status.OK.getStatusCode());
    assertThat(response.getHeader("Access-Control-Allow-Origin")).isEqualTo("*");
    assertThat(response.getHeader("Access-Control-Allow-Methods"))
        .isEqualTo("POST, GET, UPDATE, DELETE, OPTIONS");
    assertThat(response.getHeader("Access-Control-Allow-Headers"))
        .isEqualTo("content-type, x-http-method-override");
  }
コード例 #2
0
 public String createDir(String user, String password, String dir, String permsOctal, int status) {
   getMock("WEBHDFS")
       .expect()
       .method("PUT")
       .pathInfo("/v1" + dir)
       .queryParam("op", "MKDIRS")
       .queryParam("user.name", user)
       .queryParam("permission", permsOctal)
       .respond()
       .status(HttpStatus.SC_OK)
       .contentType("application/json")
       .content("{\"boolean\": true}".getBytes());
   Response response =
       given()
           // .log().all()
           .auth()
           .preemptive()
           .basic(user, password)
           .header("X-XSRF-Header", "jksdhfkhdsf")
           .queryParam("op", "MKDIRS")
           .queryParam("permission", permsOctal)
           .expect()
           // .log().all()
           .statusCode(status)
           .contentType("application/json")
           .content("boolean", equalTo(true))
           .when()
           .put(getUrl("WEBHDFS") + "/v1" + dir + (isUseGateway() ? "" : "?user.name=" + user));
   String location = response.getHeader("Location");
   return location;
 }
コード例 #3
0
  @Test
  /* low level */ public void whenResourceIsCreated_thenALocationIsReturnedToTheClient() {
    // When
    final Response response = getApi().createAsResponse(createNewResource());

    // Then
    assertNotNull(response.getHeader(HttpHeaders.LOCATION));
  }
コード例 #4
0
ファイル: ChannelSetUpTest.java プロジェクト: icyerasor/joynr
  @Test
  public void testCreateChannelThatIsAlreadyKnown() {

    Mockito.when(mock.getChannel("channel-123"))
        .thenReturn(createChannel("X.Y", "http://joyn-bpX.de/bp", "channel-123"));

    Response response = //
        given()
            . //
            when()
            .post(serverUrl + "?ccid=channel-123");

    assertEquals(200 /* OK */, response.getStatusCode());
    assertEquals("http://joyn-bpX.de/bp/channels/channel-123", response.getHeader("Location"));
    assertEquals("http://joyn-bpX.de/bp/channels/channel-123", response.getBody().asString());
    assertEquals("X.Y", response.getHeader("bp"));
    Mockito.verify(mock).getChannel("channel-123");
    Mockito.verifyNoMoreInteractions(mock);
  }
コード例 #5
0
 public String updateFileNN(String user, String password, String file, String resource, int status)
     throws IOException {
   if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
     getMock("WEBHDFS")
         .expect()
         .method("PUT")
         .pathInfo("/v1" + file)
         .queryParam("op", "CREATE")
         .queryParam("user.name", user)
         .queryParam("overwrite", "true")
         .respond()
         .status(status)
         .header("Location", getRealUrl("DATANODE") + file + "?op=CREATE&user.name=" + user);
   } else {
     getMock("WEBHDFS")
         .expect()
         .method("PUT")
         .pathInfo("v1" + file)
         .queryParam("user.name", user)
         .queryParam("op", "CREATE")
         .respond()
         .status(status);
   }
   Response response =
       given()
           // .log().all()
           .auth()
           .preemptive()
           .basic(user, password)
           .header("X-XSRF-Header", "jksdhfkhdsf")
           .queryParam("op", "CREATE")
           .queryParam("overwrite", "true")
           .content(getResourceBytes(resource))
           .expect()
           // .log().all()
           .statusCode(status)
           .when()
           .put(getUrl("WEBHDFS") + "/v1" + file + (isUseGateway() ? "" : "?user.name=" + user));
   String location = response.getHeader("Location");
   log.trace("Redirect location: " + response.getHeader("Location"));
   return location;
 }
コード例 #6
0
ファイル: ChannelSetUpTest.java プロジェクト: icyerasor/joynr
  @Test
  public void testCreateNewChannel() {

    Mockito.when(mock.getChannel("channel-123")).thenReturn(null);
    Mockito.when(mock.createChannel("channel-123", null))
        .thenReturn(createChannel("0.0", "http://joyn-bp0.de/bp", "channel-123"));

    Response response = //
        given()
            . //
            when()
            .post(serverUrl + "?ccid=channel-123");

    assertEquals(201 /* Created */, response.getStatusCode());
    assertEquals("http://joyn-bp0.de/bp/channels/channel-123", response.getHeader("Location"));
    assertEquals("http://joyn-bp0.de/bp/channels/channel-123", response.getBody().asString());
    assertEquals("0.0", response.getHeader("bp"));
    Mockito.verify(mock).getChannel("channel-123");
    Mockito.verify(mock).createChannel("channel-123", null);
    Mockito.verifyNoMoreInteractions(mock);
  }
コード例 #7
0
 @Test(
     groups = {MUST},
     description =
         "LDP servers exposing LDPRs MUST advertise "
             + "their LDP support by exposing a HTTP Link header "
             + "with a target URI of http://www.w3.org/ns/ldp#Resource, "
             + "and a link relation type of type (that is, rel='type') "
             + "in all responses to requests made to the LDPR's "
             + "HTTP Request-URI.")
 @SpecTest(
     specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-gen-linktypehdr",
     testMethod = METHOD.AUTOMATED,
     approval = STATUS.WG_APPROVED)
 public void testLdpLinkHeader() {
   final String uri = getResourceUri();
   Response response = buildBaseRequestSpecification().when().get(getResourceUri());
   assertTrue(
       containsLinkHeader(uri, LINK_REL_TYPE, LDP.Resource.stringValue(), uri, response),
       "4.2.1.4 LDP servers exposing LDPRs must advertise their LDP support by exposing a HTTP Link header "
           + "with a target URI of http://www.w3.org/ns/ldp#Resource, and a link relation type of type (that is, "
           + "rel='type') in all responses to requests made to the LDPR's HTTP Request-URI. Actual: "
           + response.getHeader(LINK));
 }
コード例 #8
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");
  }