com.jayway.restassured.response.Response.getHeader()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.jayway.restassured.response.Response.getHeader方法的一些代码示例,展示了Response.getHeader的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getHeader方法的具体详情如下:
包路径:com.jayway.restassured.response.Response
类名称:Response
方法名:getHeader

Response.getHeader介绍

暂无

代码示例

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {MAY},
    description = "LDP servers may accept an HTTP POST of non-RDF " +
        "representations (LDP-NRs) for creation of any kind of " +
        "resource, for example binary resources.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-createbins",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED,
    comment = "Covers only part of the specification requirement. "
        + "testPostResourceAndGetFromContainer covers the rest.")
public void testPostNonRDFSource() throws IOException {
  // Test constants
  final String slug = "test",
      file = slug + ".png",
      mimeType = "image/png";
  // Make sure we can post binary resources
  Response response = postNonRDFSource(slug, file, mimeType);
  buildBaseRequestSpecification().delete(response.getHeader(LOCATION));
}

代码示例来源:origin: org.w3/ldp-testsuite

nonRdfSource = response.getHeader(LOCATION);
if (nonRdfSource == null) {
  System.err.println(SETUP_ERROR);

代码示例来源:origin: org.w3/ldp-testsuite

/**
 * Attempts to create a new resource using PUT.
 *
 * @return the location of the created resource
 * @see #testPutToCreate()
 * @see #testRestrictPutReUseUri()
 */
protected String putToCreate() {
  // Build a unique URI for the PUT request.
  URI target = UriBuilder.fromUri(getResourceUri())
      .path(UUID.randomUUID().toString()).build();
  Model model = postContent();
  Response response = buildBaseRequestSpecification().contentType(TEXT_TURTLE)
      .body(model, new RdfObjectMapper("")).expect()
      .statusCode(HttpStatus.SC_CREATED).when().put(target);
  String location = response.getHeader(LOCATION);
  if (location == null) {
    return target.toString();
  }
  return location;
}

代码示例来源:origin: org.w3/ldp-testsuite

private String post(Model content, String slug) {
  RequestSpecification spec = buildBaseRequestSpecification().contentType(TEXT_TURTLE);
  if (slug != null) {
    spec.header(SLUG, slug);
  }
  Response post = spec.body(content, new RdfObjectMapper()).expect()
      .statusCode(HttpStatus.SC_CREATED).when()
      .post(getResourceUri());
  String location = post.getHeader(LOCATION);
  assertNotNull(location, MSG_LOC_NOTFOUND);
  return location;
}

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {MUST},
    description = "LDP servers that successfully create a resource from a "
        + "RDF representation in the request entity body MUST honor the "
        + "client's requested interaction model(s). The created resource "
        + "can be thought of as an RDF named graph [rdf11-concepts]. If any "
        + "model cannot be honored, the server MUST fail the request.")
@Parameters("containerAsResource")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-createrdf",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED,
    comment = "Covers only part of the specification requirement. "
        + "testRequestedInteractionModelHeaders covers the rest.")
public void testRequestedInteractionModelCreateNotAllowed(@Optional String containerAsResource) {
  if (containerAsResource == null)
    throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(),
        "containerAsResource is null", skipLog);
  Model model = postContent();
  // If create is successful, then not acting like a plain ole resource
  Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE)
      .body(model, new RdfObjectMapper())
      .post(containerAsResource);
  // Cleanup if it actually created something
  String location = postResponse.getHeader(LOCATION);
  if (postResponse.statusCode() == HttpStatus.SC_CREATED && location !=null)
    buildBaseRequestSpecification().delete(location);
  assertNotEquals(postResponse.statusCode(), HttpStatus.SC_CREATED, "Resources with interaction model of only ldp:Resources shouldn't allow container POST-create behavior.");
  // TODO: Possibly parse 'Allow' header to see if POST is wrongly listed
}

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {MUST},
    description = "LDP servers that support POST MUST include an Accept-Post "
        + "response header on HTTP OPTIONS responses, listing post document "
        + "media type(s) supported by the server.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-acceptposthdr",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testAcceptPostResponseHeader() {
  skipIfMethodNotAllowed(HttpMethod.POST);
  Response optionsResponse = buildBaseRequestSpecification().expect()
      .statusCode(isSuccessful()).when()
      .options(getResourceUri());
  assertNotNull(
      optionsResponse.getHeader(ACCEPT_POST),
      "The HTTP OPTIONS response on container <"
          + getResourceUri()
          + "> did not include an Accept-Post response header, but it lists POST in its Allow response header."
  );
}

代码示例来源:origin: org.w3/ldp-testsuite

.header(ETAG, HeaderMatchers.isValidEntityTag())
    .when()
      .get(response.getHeader(LOCATION))
      .body().asByteArray();
  assertEquals(expectedMD5, HashUtils.md5sum(binary), "md5sum");
} finally {
  buildBaseRequestSpecification().delete(response.getHeader(LOCATION));

代码示例来源:origin: org.w3/ldp-testsuite

String location = postResponse.getHeader(LOCATION);

代码示例来源:origin: org.w3/ldp-testsuite

.body().as(Model.class, new RdfObjectMapper(container));
  assertTrue(model.contains(model.createResource(container), model.createProperty(LDP.contains.stringValue()), model.createResource(response.getHeader(LOCATION))));
} finally {
  buildBaseRequestSpecification().delete(response.getHeader(LOCATION));

代码示例来源:origin: org.w3/ldp-testsuite

protected Response expectPut4xxStatus(String invalidProp) {
  // Get the resource.
  String resourceUri = getResourceUri();
  Response getResponse = buildBaseRequestSpecification()
    .expect()
      .statusCode(isSuccessful())
      .header(ETAG, isValidEntityTag())
    .when()
      .get(resourceUri);
  String eTag = getResponse.getHeader(ETAG);
  Model m = getResponse.as(Model.class, new RdfObjectMapper(resourceUri));
  modifyProperty(m, resourceUri, invalidProp);
  Response putResponse = buildBaseRequestSpecification()
      .contentType(TEXT_TURTLE)
      .header(IF_MATCH, eTag)
      .body(m, new RdfObjectMapper(resourceUri))
    .when()
      .put(resourceUri);
  if (isSuccessful().matches(putResponse.getStatusCode())) {
    throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(),
        "Skipping test because PUT request was successful.", skipLog);
  }
  assertThat(putResponse.statusCode(), is4xxRange());
  return putResponse;
}

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {MUST},
    description = "If the resource was created successfully, LDP servers MUST "
        + "respond with status code 201 (Created) and the Location "
        + "header set to the new resource’s URL. Clients shall not "
        + "expect any representation in the response entity body on "
        + "a 201 (Created) response.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-created201",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testPostResponseStatusAndLocation() throws URISyntaxException {
  skipIfMethodNotAllowed(HttpMethod.POST);
  String location = null;
  try {
    Model model = postContent();
    Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE)
        .body(model, new RdfObjectMapper()).expect()
        .statusCode(HttpStatus.SC_CREATED).when()
        .post(getResourceUri());
    location = postResponse.getHeader(LOCATION);
    assertNotNull(location, MSG_LOC_NOTFOUND);
  } finally {
    buildBaseRequestSpecification().delete(location);
  }
}

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {MUST},
    description = "LDP servers MUST accept a request entity body with a "
        + "request header of Content-Type with value of text/turtle [turtle].")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-turtle",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testAcceptTurtle() {
  skipIfMethodNotAllowed(HttpMethod.POST);
  Model model = postContent();
  Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE)
      .body(model, new RdfObjectMapper()).expect()
      .statusCode(HttpStatus.SC_CREATED).when()
      .post(getResourceUri());
  // Delete the resource to clean up.
  String location = postResponse.getHeader(LOCATION);
  if (location != null) {
    buildBaseRequestSpecification().delete(location);
  }
}

代码示例来源:origin: org.w3/ldp-testsuite

final String location = postResponse.getHeader(LOCATION);

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {SHOULD},
    description = "LDP servers SHOULD assign the URI for the resource to be created "
        + "using server application specific rules in the absence of a client hint.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-serverassignuri",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testPostNoSlug() {
  skipIfMethodNotAllowed(HttpMethod.POST);
  // POST content with no Slug and see if the server assigns a URI.
  Model model = postContent();
  Response postResponse = buildBaseRequestSpecification()
      .contentType(TEXT_TURTLE)
      .body(model, new RdfObjectMapper())
     .expect()
      .statusCode(HttpStatus.SC_CREATED)
      .header(LOCATION, HeaderMatchers.headerPresent())
    .when()
      .post(getResourceUri());
  // Delete the resource to clean up.
  buildBaseRequestSpecification().delete(postResponse.getHeader(LOCATION));
}

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {SHOULD},
    description = "LDP servers SHOULD allow clients to create new resources without "
        + "requiring detailed knowledge of application-specific constraints. This "
        + "is a consequence of the requirement to enable simple creation and "
        + "modification of LDPRs. LDP servers expose these application-specific "
        + "constraints as described in section 4.2.1 General.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-mincontraints",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testCreateWithoutConstraints() throws URISyntaxException {
  skipIfMethodNotAllowed(HttpMethod.POST);
  // Create a resource with one statement (dcterms:title).
  Model requestModel = ModelFactory.createDefaultModel();
  Resource resource = requestModel.createResource("");
  resource.addProperty(DCTerms.title, "Created by the LDP test suite");
  Response postResponse = buildBaseRequestSpecification()
        .contentType(TEXT_TURTLE)
        .body(requestModel, new RdfObjectMapper())
      .expect()
        .statusCode(HttpStatus.SC_CREATED)
      .when()
        .post(getResourceUri());
  // Delete the resource to clean up.
  String location = postResponse.getHeader(LOCATION);
  if (location != null) {
    buildBaseRequestSpecification().delete(location);
  }
}

代码示例来源:origin: ldp4j/ldp4j

when().
    get(path);
assertThat(response.getHeader("Link"),containsString(link));
LOGGER.info("Completed {}",pName);

代码示例来源:origin: org.w3/ldp-testsuite

@Test(
    groups = {SHOULD},
    description = "LDP servers SHOULD NOT allow HTTP PUT to update an LDPC’s "
        + "containment triples; if the server receives such a request, it "
        + "SHOULD respond with a 409 (Conflict) status code.")
@SpecTest(
    specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-put-mbrprops",
    testMethod = METHOD.AUTOMATED,
    approval = STATUS.WG_APPROVED)
public void testRejectPutModifyingContainmentTriples() {
  String containerUri = getResourceUri();
  Response response = buildBaseRequestSpecification()
      .header(ACCEPT, TEXT_TURTLE)
      .expect().statusCode(isSuccessful())
      .when().get(containerUri);
  String eTag = response.getHeader(ETAG);
  Model model = response.as(Model.class, new RdfObjectMapper(containerUri));
  // Try to modify the ldp:contains triple.
  Resource containerResource = model.getResource(containerUri);
  containerResource.addProperty(model.createProperty(LDP.contains.stringValue()),
      model.createResource("#" + System.currentTimeMillis()));
  RequestSpecification putRequest = buildBaseRequestSpecification().contentType(TEXT_TURTLE);
  if (eTag != null) {
    putRequest.header(IF_MATCH, eTag);
  }
  putRequest.body(model, new RdfObjectMapper(containerUri))
      .expect().statusCode(not(isSuccessful()))
      .when().put(containerUri);
}

代码示例来源:origin: org.w3/ldp-testsuite

final String location = postResponse.getHeader(LOCATION);
Response getResponse = buildBaseRequestSpecification()
  .expect()

代码示例来源:origin: org.w3/ldp-testsuite

.when().post(directContainer);
String location = postResponse.getHeader(LOCATION);
try {
  Response getResponse = buildBaseRequestSpecification()

代码示例来源:origin: org.w3/ldp-testsuite

.post(containerUri);
String location = postResponse.getHeader(LOCATION);

相关文章