Skip to content

Commit

Permalink
Enhance multi-module check for run goal
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wisniewski <[email protected]>
  • Loading branch information
Adam Wisniewski authored and Adam Wisniewski committed Mar 5, 2024
1 parent adae635 commit f247868
Show file tree
Hide file tree
Showing 28 changed files with 1,226 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ multipleLibertyModules)  pom, ear1+war+jar, ear2+war+jar
- Main pom: ./pom.xml
- Tests exist in every module

multipleLibertyModules-skip-conflicts)  pom, ear1+war+jar, ear2+war+jar, jar2
- Server info in ear1 and ear2 modules
- Main pom: ./pom.xml
- Tests exist in every module
- ear2 has <skip>true</skip> configured in LMP configuration

sample.ejb) pom, ear+war+ejb
- Based on https://github.com/WASdev/sample.ejb

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-ear1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Liberty configuration -->
<liberty.var.default.http.port>9080</liberty.var.default.http.port>
<liberty.var.default.https.port>9443</liberty.var.default.https.port>
<!-- Test Configuration -->
<!-- <skipTests>true</skipTests> -->
<!-- <skipITs>true</skipITs> -->
<!-- <skipUTs>true</skipUTs> -->
</properties>
<repositories>
<!-- Sonatype repository used to get the latest binary scanner jar -->
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<dependencies>
<!-- web and jar modules as dependencies -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<!-- For tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<modules>
<jarModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<uri>/guide-maven-multimodules-jar-1.0-SNAPSHOT.jar</uri>
</jarModule>
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<uri>/guide-maven-multimodules-war-1.0-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/converter</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>

<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>SUB_VERSION</version>
</plugin>

<!-- Since the package type is ear,
need to run testCompile to compile the tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<default.http.port>
${liberty.var.default.http.port}
</default.http.port>
<default.https.port>
${liberty.var.default.https.port}
</default.https.port>
<cf.context.root>/converter</cf.context.root>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<server description="Sample Liberty server">

<featureManager>
<feature>jsp-2.3</feature>
</featureManager>

<variable name="default.http.port" defaultValue="9080" />
<variable name="default.https.port" defaultValue="9443" />

<httpEndpoint host="*" httpPort="${default.http.port}"
httpsPort="${default.https.port}" id="defaultHttpEndpoint" />

<enterpriseApplication id="guide-maven-multimodules-ear1"
location="guide-maven-multimodules-ear1.ear"
name="guide-maven-multimodules-ear1" />
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
package it.io.openliberty.guides.multimodules;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.jupiter.api.Test;

public class ConverterAppIT {
String port = System.getProperty("default.http.port");
String war = "converter";
String urlBase = "http://localhost:" + port + "/" + war + "/";

@Test
public void testIndexPage() throws Exception {
String url = this.urlBase;
HttpURLConnection con = testRequestHelper(url, "GET");
assertEquals(200, con.getResponseCode(), "Incorrect response code from " + url);
assertTrue(testBufferHelper(con).contains("Enter the height in centimeters"),
"Incorrect response from " + url);
}

@Test
public void testHeightsPage() throws Exception {
String url = this.urlBase + "heights.jsp?heightCm=10";
HttpURLConnection con = testRequestHelper(url, "POST");
assertTrue(testBufferHelper(con).contains("3 inches"),
"Incorrect response from " + url);
}

private HttpURLConnection testRequestHelper(String url, String method)
throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod(method);
return con;
}

private String testBufferHelper(HttpURLConnection con) throws Exception {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-ear2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Liberty configuration -->
<liberty.var.default.http.port>9081</liberty.var.default.http.port>
<liberty.var.default.https.port>9444</liberty.var.default.https.port>
<!-- Test Configuration -->
<!-- <skipTests>true</skipTests> -->
<!-- <skipITs>true</skipITs> -->
<!-- <skipUTs>true</skipUTs> -->
</properties>
<repositories>
<!-- Sonatype repository used to get the latest binary scanner jar -->
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<dependencies>
<!-- web and jar modules as dependencies -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<!-- For tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<modules>
<jarModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<uri>/guide-maven-multimodules-jar-1.0-SNAPSHOT.jar</uri>
</jarModule>
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<uri>/guide-maven-multimodules-war-1.0-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/converter</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>

<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>SUB_VERSION</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<!-- Since the package type is ear,
need to run testCompile to compile the tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<default.http.port>
${liberty.var.default.http.port}
</default.http.port>
<default.https.port>
${liberty.var.default.https.port}
</default.https.port>
<cf.context.root>/converter</cf.context.root>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<server description="Sample Liberty server">

<featureManager>
<feature>jsp-2.3</feature>
</featureManager>

<variable name="default.http.port" defaultValue="9080" />
<variable name="default.https.port" defaultValue="9443" />

<httpEndpoint host="*" httpPort="${default.http.port}"
httpsPort="${default.https.port}" id="defaultHttpEndpoint" />

<enterpriseApplication id="guide-maven-multimodules-ear2"
location="guide-maven-multimodules-ear2.ear"
name="guide-maven-multimodules-ear2" />
</server>
Loading

0 comments on commit f247868

Please sign in to comment.