Skip to content

Commit

Permalink
Fixes piranhacloud#4169 - Add Piranha Web Profile distribution integr…
Browse files Browse the repository at this point in the history
…ation tests
  • Loading branch information
mnriem committed Nov 5, 2024
1 parent 95333a1 commit 8a76ce8
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ private String toAppName(Archive<?> archive) {
private File getPiranhaJarFile(String version) throws IOException {
URL downloadUrl = createMavenCentralArtifactUrl(
"cloud.piranha.dist",
"piranha-dist-coreprofile",
"piranha-dist-" + configuration.getDistribution(),
version,
"jar"
);

String artifactPath = createArtifactPath(
"cloud.piranha.dist",
"piranha-dist-coreprofile",
"piranha-dist-" + configuration.getDistribution(),
version,
"jar"
);
Expand Down Expand Up @@ -348,11 +348,16 @@ private void startPiranha(File runtimeDirectory, File warFile) throws IOExceptio

if (classpath.isEmpty()) {
commands.add("-jar");
commands.add("piranha-dist-coreprofile.jar");
commands.add("piranha-" + configuration.getDistribution() + ".jar");
} else {
commands.add("-cp");
commands.add(classpath.toString() + "piranha-dist-coreprofile.jar");
commands.add("cloud.piranha.dist.coreprofile.CoreProfilePiranhaMain");
commands.add(classpath.toString() + "piranha-" + configuration.getDistribution() + ".jar");
if (configuration.getDistribution().equals("coreprofile")) {
commands.add("cloud.piranha.dist.coreprofile.CoreProfilePiranhaMain");
}
if (configuration.getDistribution().equals("webprofile")) {
commands.add("cloud.piranha.dist.webprofile.WebProfilePiranhaMain");
}
}
commands.add("--http-port");
commands.add(Integer.toString(configuration.getHttpPort()));
Expand All @@ -370,13 +375,15 @@ private void startPiranha(File runtimeDirectory, File warFile) throws IOExceptio
Starting Piranha
Directory: {0}
Log: {1}
URL: {2}
Classpath: {0}
Directory: {1}
Log: {2}
URL: {3}
""",

classpath.toString(),
runtimeDirectory,
logFile.getAbsolutePath(),
appURL);
Expand Down Expand Up @@ -443,7 +450,7 @@ private void copyPiranhaJarFile(File runtimeDirectory, File zipFile) throws IOEx
}

Files.copy(zipFile.toPath(),
Path.of(runtimeDirectory + "/piranha-dist-coreprofile.jar"),
Path.of(runtimeDirectory + "/piranha-" + configuration.getDistribution() + ".jar"),
REPLACE_EXISTING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
* <td>not enabled by default</td>
* </tr>
* <tr>
* <td>piranha.distribution</td>
* <td>The Piranha distribution to use</td>
* <td>coreprofile by default</td>
* </tr>
* <tr>
* <td>piranha.httpPort</td>
* <td>The integer to select the HTTP port to use for the Piranha process</td>
* <td>if not set an unused port will be automatically chosen</td>
Expand Down Expand Up @@ -83,6 +88,11 @@ public class ManagedPiranhaContainerConfiguration implements ContainerConfigurat
*/
private static final System.Logger LOGGER = System.getLogger(ManagedPiranhaContainerConfiguration.class.getName());

/**
* Stores the distribution to use.
*/
private String distribution = System.getProperty("piranha.distribution", "coreprofile");

/**
* Stores the debug flag.
*/
Expand Down Expand Up @@ -113,6 +123,15 @@ public class ManagedPiranhaContainerConfiguration implements ContainerConfigurat
*/
public ManagedPiranhaContainerConfiguration() {
}

/**
* Get the distribution.
*
* @return the distribution.
*/
public String getDistribution() {
return distribution;
}

/**
* Get the HTTP port.
Expand Down Expand Up @@ -171,6 +190,15 @@ public void setDebug(boolean debug) {
this.debug = debug;
}

/**
* Set the distribution.
*
* @param distribution the distribution.
*/
public void setDistribution(String distribution) {
this.distribution = distribution;
}

/**
* Set the HTTP port.
*
Expand Down
67 changes: 14 additions & 53 deletions test/webprofile/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
</properties>
<dependencies>
<!-- provided -->
<dependency>
<groupId>cloud.piranha.dist</groupId>
<artifactId>piranha-dist-webprofile</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-core-api</artifactId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>cloud.piranha.arquillian</groupId>
<artifactId>piranha-arquillian-managed</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -49,32 +55,6 @@
<build>
<finalName>piranha-test-webprofile-integration</finalName>
<plugins>
<plugin>
<groupId>cloud.piranha.maven</groupId>
<artifactId>piranha-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<contextPath>/integration</contextPath>
<distribution>webprofile</distribution>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand All @@ -87,9 +67,8 @@
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
<piranha.distribution>webprofile</piranha.distribution>
</systemPropertyVariables>
</configuration>
</plugin>
Expand All @@ -100,24 +79,6 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>package</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 8a76ce8

Please sign in to comment.