Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {

// test dependencies
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'commons-httpclient:commons-httpclient:3.1'
testImplementation 'org.apache.httpcomponents.client5:httpclient5:5.6.1'

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 2026 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,32 +13,28 @@
package test.gradle.liberty.web.app.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.EntityUtils;

public class EndpointIT {
private String URL = "http://localhost:9080/liberty-gradle-test-wrapper-app/servlet";

@Test
public void testServlet() throws Exception {
System.out.println("am ere");
HttpClient client = new HttpClient();

GetMethod method = new GetMethod(URL);

try {
int statusCode = client.executeMethod(method);

Assertions.assertEquals(HttpStatus.SC_OK, statusCode, "HTTP GET failed");

String response = method.getResponseBodyAsString(1000);

Assertions.assertTrue(response.contains("Hello! How are you today?"), "Unexpected response body");
} finally {
method.releaseConnection();
}
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet request = new HttpGet(URL);
try (CloseableHttpResponse response = client.execute(request)) {
int statusCode = response.getCode();
String responseBody = EntityUtils.toString(response.getEntity());

Assertions.assertEquals(HttpStatus.SC_OK, statusCode, "HTTP GET failed");
Assertions.assertTrue(responseBody.contains("Hello! How are you today?"), "Unexpected response body");
}
}
}
}
14 changes: 7 additions & 7 deletions src/test/resources/maven/liberty-maven-test-wrapper-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<artifactId>liberty-maven-test-wrapper-app</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<packaging.type>minify,runnable</packaging.type>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -36,9 +36,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -48,7 +48,7 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
Expand Down Expand Up @@ -85,4 +85,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 2026 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,32 +13,28 @@
package test.maven.liberty.web.app.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.EntityUtils;

public class EndpointIT {
private String URL = "http://localhost:9080/liberty-maven-test-wrapper-app/servlet";

@Test
public void testServlet() throws Exception {
HttpClient client = new HttpClient();

GetMethod method = new GetMethod(URL);
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet request = new HttpGet(URL);
try (CloseableHttpResponse response = client.execute(request)) {
int statusCode = response.getCode();
String responseBody = EntityUtils.toString(response.getEntity());

try {
int statusCode = client.executeMethod(method);

Assertions.assertEquals(HttpStatus.SC_OK, statusCode, "HTTP GET failed");

String response = method.getResponseBodyAsString(1000);

Assertions.assertTrue(response.contains("Hello! How are you today?"), "Unexpected response body");
} finally {
method.releaseConnection();
}
Assertions.assertEquals(HttpStatus.SC_OK, statusCode, "HTTP GET failed");
Assertions.assertTrue(responseBody.contains("Hello! How are you today?"), "Unexpected response body");
}
}
}
}
Loading