@Test
 public void mergesHeadersCorrectlyWhenUsingGivenSpecRequestSpec() {
   given()
       .spec(jsonRequest)
       .filter(
           (requestSpec, responseSpec, ctx) -> {
             Headers headers = requestSpec.getHeaders();
             assertThat(
                 requestSpec.getRequestContentType(),
                 equalTo(
                     "application/json; charset="
                         + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
             assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
             assertThat(headers.getValue("accept"), equalTo("application/json+json"));
             assertThat(
                 headers.getValue("content-type"),
                 equalTo(
                     "application/json; charset="
                         + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
             assertThat(headers.size(), is(3));
             return new ResponseBuilder().setStatusCode(200).build();
           })
       .when()
       .get();
 }
 @Test
 public void mergesHeadersCorrectlyWhenOnlyStaticMerging() {
   given()
       .filter(
           (requestSpec, responseSpec, ctx) -> {
             Headers headers = requestSpec.getHeaders();
             assertThat(requestSpec.getRequestContentType(), nullValue());
             assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
             assertThat(headers.getValue("accept"), equalTo("*/*"));
             assertThat(headers.size(), is(2));
             return new ResponseBuilder().setStatusCode(200).build();
           })
       .when()
       .get();
 }
Пример #3
0
 @BeforeClass(alwaysRun = true)
 public void determineOptions() {
   String uri = getResourceUri();
   if (StringUtils.isNotBlank(uri)) {
     // Use HTTP OPTIONS, which MUST be supported by LDP servers, to determine what methods are
     // supported on this container.
     Response optionsResponse = buildBaseRequestSpecification().options(uri);
     Headers headers = optionsResponse.getHeaders();
     List<Header> allowHeaders = headers.getList(ALLOW);
     for (Header allowHeader : allowHeaders) {
       String allow = allowHeader.getValue();
       if (allow != null) {
         String[] methods = allow.split("\\s*,\\s*");
         for (String method : methods) {
           options.add(method);
         }
       }
     }
   }
 }