View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.http.response;
6   
7   import com.jcabi.http.request.JdkRequest;
8   import java.io.IOException;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Assertions;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Integration test for {@link RestResponse}.
16   *
17   * @since 1.17.5
18   */
19  @SuppressWarnings("PMD.AvoidDuplicateLiterals") final class RestResponseITCase {
20      @Test
21      void readsCookiesSeveralValues() throws IOException {
22          final RestResponse resp = new JdkRequest(
23              "https://httpbin.org/cookies/set?ijk=efg&xyz=abc"
24          )
25              .fetch()
26              .as(RestResponse.class);
27          Assertions.assertAll(
28              () -> MatcherAssert.assertThat(
29                  "should contains value 'efg'",
30                  resp.cookie("ijk"),
31                  Matchers.hasProperty("value", Matchers.is("efg"))
32              ),
33              () -> MatcherAssert.assertThat(
34                  "should contains value 'abc'",
35                  resp.cookie("xyz"),
36                  Matchers.hasProperty("value", Matchers.is("abc"))
37              )
38          );
39      }
40  
41      @Test
42      void readsCookies() throws IOException {
43          MatcherAssert.assertThat(
44              "should contains value 'bar'",
45              new JdkRequest("https://httpbin.org/cookies/set?foo=bar")
46                  .fetch()
47                  .as(RestResponse.class)
48                  .cookie("foo"),
49              Matchers.hasProperty("value", Matchers.is("bar"))
50          );
51      }
52  }