diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml
new file mode 100644
index 0000000..7c1ad6b
--- /dev/null
+++ b/.github/workflows/integration-tests.yml
@@ -0,0 +1,63 @@
+name: Integration Tests
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ integration-tests:
+ name: Run Integration Tests
+ runs-on: ubuntu-latest
+ services:
+ httpbin:
+ image: kennethreitz/httpbin
+ ports:
+ - 31888:80
+ steps:
+
+ - name: Wait for httpbin to be ready
+ run: |
+ for i in {1..10}; do
+ if curl -sSf http://localhost:31888/get >/dev/null; then
+ echo "httpbin is ready!"
+ exit 0
+ fi
+ echo "Waiting for httpbin..."
+ sleep 3
+ done
+ echo "httpbin did not start in time" >&2
+ exit 1
+
+ - name: Checkout Repository
+ uses: actions/checkout@v4
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v4
+ with:
+ java-version: "17"
+ distribution: temurin
+ cache: maven
+
+ - name: Set up Maven settings.xml
+ uses: s4u/maven-settings-action@v3.1.0
+ with:
+ sonatypeSnapshots: true
+ repositories: >-
+ [
+ {
+ "id": "central-snapshots",
+ "name": "Maven Repository Switchboard",
+ "url": "https://central.sonatype.com/repository/maven-snapshots",
+ "snapshots": { "enabled": true },
+ "releases": { "enabled": false }
+ }
+ ]
+
+ - name: Run Integration Tests
+ env:
+ HTTPBIN_BASE_URL: http://localhost:31888
+ run: |
+ mvn clean -B verify -Pintegration-tests \
+ -Dhttpbin.url=$HTTPBIN_BASE_URL
diff --git a/pom.xml b/pom.xml
index c0f115b..83935b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
http://httpbin.org
- *
- * When running tests, you can set the HTTPBIN_URL environment variable
- * to specify another address where httpbin is running.
- *
- * Example: - *
- *HTTPBIN_URL=http://httpbin.example.org:8080
+ * Get the HTTPBIN_BASE_URL provided by the system property. This must be set
+ * before running the tests, for example:
+ * -Dhttpbin.url=https://httpbin.org
*/
- private static final String HTTPBIN_URL;
+ private static final String HTTPBIN_BASE_URL;
static {
- String url = System.getenv("HTTPBIN_URL");
+ String url = System.getProperty("httpbin.url");
if (url == null || url.isEmpty()) {
- url = "http://httpbin.org";
+ throw new IllegalStateException("httpbin.url system property must be set");
}
- HTTPBIN_URL = url;
- }
-
- /**
- * By default, HTTPBIN_SSL_URL points to the public instance of httpbin:
- * https://httpbin.org
- *
- * When running tests, you can set the HTTPBIN_SSL_URL environment variable
- * to specify another address where httpbin is running.
- *
- * Example: - *
- *HTTPBIN_URL=https://httpbin.example.org:8082
- */
- private static final String HTTPBIN_SSL_URL;
-
- static {
- String url = System.getenv("HTTPBIN_SSL_URL");
- if (url == null || url.isEmpty()) {
- url = "https://httpbin.org";
- }
- HTTPBIN_SSL_URL = url;
+ HTTPBIN_BASE_URL = url;
}
@ParameterizedTest
@@ -111,9 +82,9 @@ class HttpClientTest {
524
}
)
- void statusCode(int status) throws Exception {
+ void testStatusCode(int status) throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/status/" + status,
+ HTTPBIN_BASE_URL + "/status/" + status,
"GET",
null,
null,
@@ -132,70 +103,11 @@ void statusCode(int status) throws Exception {
assertEquals(status, r.getStatusCode(), "Must return status " + status);
}
- @Test
- void https() throws Exception {
- HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_SSL_URL + "/status/200",
- "GET",
- null,
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
- null,
- null,
- 30,
- null
- );
- assertEquals(200, r.getStatusCode(), "Default https must work");
-
- r =
- HttpClient.sendRequest(
- HTTPBIN_SSL_URL + "/status/200",
- "GET",
- new String[] { "TLSv1.2" },
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
- null,
- null,
- 30,
- null
- );
- assertEquals(200, r.getStatusCode(), "TLSv1.2 only must work");
-
- r =
- HttpClient.sendRequest(
- HTTPBIN_SSL_URL + "/status/200",
- "GET",
- new String[] { "SSLv2Hello" },
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
- null,
- null,
- 30,
- null
- );
- assertEquals(200, r.getStatusCode(), "Specifying SSLv2Hello must not break communication");
- }
-
@ParameterizedTest
@ValueSource(strings = { "GET", "DELETE", "POST", "PUT" })
- void method(String method) throws Exception {
+ void testMethod(String method) throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/" + method.toLowerCase(),
+ HTTPBIN_BASE_URL + "/" + method.toLowerCase(),
method,
null,
null,
@@ -215,9 +127,9 @@ void method(String method) throws Exception {
}
@Test
- void basicAuth() throws Exception {
+ void testBasicAuth() throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/basic-auth/mypasswordis/password",
+ HTTPBIN_BASE_URL + "/basic-auth/mypasswordis/password",
"GET",
null,
"mypasswordis",
@@ -236,9 +148,9 @@ void basicAuth() throws Exception {
}
@Test
- void basicAuthFail() throws Exception {
+ void testBasicAuthFail() throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/basic-auth/mypasswordis/notpassword",
+ HTTPBIN_BASE_URL + "/basic-auth/mypasswordis/notpassword",
"GET",
null,
"mypasswordis",
@@ -257,9 +169,9 @@ void basicAuthFail() throws Exception {
}
@Test
- void digestAuth() throws Exception {
+ void testDigestAuth() throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/digest-auth/auth/mypasswordis/password",
+ HTTPBIN_BASE_URL + "/digest-auth/auth/mypasswordis/password",
"GET",
null,
"mypasswordis",
@@ -278,9 +190,9 @@ void digestAuth() throws Exception {
}
@Test
- void userAgent() throws Exception {
+ void testUserAgent() throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/user-agent",
+ HTTPBIN_BASE_URL + "/user-agent",
"GET",
null,
null,
@@ -299,9 +211,9 @@ void userAgent() throws Exception {
}
@Test
- void userAgentDefault() throws Exception {
+ void testUserAgentDefault() throws Exception {
HttpResponse r = HttpClient.sendRequest(
- HTTPBIN_URL + "/user-agent",
+ HTTPBIN_BASE_URL + "/user-agent",
"GET",
null,
null,
@@ -320,12 +232,12 @@ void userAgentDefault() throws Exception {
}
@Test
- void headers() throws Exception {
+ void testHeaders() throws Exception {
Map