View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.http;
6   
7   import com.jcabi.http.request.ApacheRequest;
8   import com.jcabi.http.request.JdkRequest;
9   import java.net.URI;
10  import org.junit.jupiter.api.AfterAll;
11  import org.junit.jupiter.api.BeforeAll;
12  import org.junit.jupiter.api.Nested;
13  import org.junit.jupiter.api.TestInstance;
14  import org.testcontainers.containers.GenericContainer;
15  import org.testcontainers.junit.jupiter.Testcontainers;
16  import org.testcontainers.utility.DockerImageName;
17  
18  /**
19   * Integration test for {@link Request}.
20   *
21   * @since 1.17.8
22   */
23  @SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
24  @TestInstance(TestInstance.Lifecycle.PER_CLASS)
25  @Testcontainers(disabledWithoutDocker = true)
26  final class RequestSecondITCase {
27  
28      /**
29       * Container with HttpBin.
30       */
31      private final GenericContainer<?> container = new GenericContainer<>(
32          DockerImageName.parse("kennethreitz/httpbin")
33      ).withExposedPorts(80);
34  
35      @BeforeAll
36      void beforeAll() {
37          this.container.start();
38      }
39  
40      @AfterAll
41      void tearDown() {
42          this.container.stop();
43      }
44  
45      /**
46       * URI of the container.
47       * @return URI.
48       */
49      private URI uri() {
50          return URI.create(
51              String.format(
52                  "http://%s:%d",
53                  this.container.getHost(),
54                  this.container.getFirstMappedPort()
55              )
56          );
57      }
58  
59      /**
60       * Test for {@link JdkRequest}.
61       * @since 1.17.8
62       */
63      @Nested
64      final class JdkRequestITCase extends RequestITCaseTemplate {
65          JdkRequestITCase() {
66              super(JdkRequest.class, RequestSecondITCase.this.uri());
67          }
68      }
69  
70      /**
71       * Test for {@link ApacheRequest}.
72       * @since 1.17.8
73       */
74      @Nested
75      final class ApacheRequestITCase extends RequestITCaseTemplate {
76          ApacheRequestITCase() {
77              super(ApacheRequest.class, RequestSecondITCase.this.uri());
78          }
79      }
80  }