Skip to content

Commit

Permalink
Merge pull request #1425 from kathrynkodama/1394
Browse files Browse the repository at this point in the history
Improve feature generation integration tests
  • Loading branch information
kathrynkodama authored Feb 10, 2022
2 parents c403851 + 7e08887 commit 5a78c99
Show file tree
Hide file tree
Showing 24 changed files with 910 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void updatePomsTest() throws Exception {
touchFileTwice("war/pom.xml");

// Give time for recompile to occur
Thread.sleep(3000);
Thread.sleep(5000);

// count exact number of messages
// only war and ear should have had recompiles
Expand Down Expand Up @@ -122,7 +122,7 @@ public void updatePomsTest() throws Exception {

// verify that feature generation did not run since there are no source class
// files for the ear module
assertEquals("generated-features.xml was modified", newFeatureFileLastModified, newFeatureFile.lastModified());
assertEquals("generated-features.xml was modified\n" + getLogTail(), newFeatureFileLastModified, newFeatureFile.lastModified());
}

private void touchFileTwice(String path) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM openliberty/open-liberty:kernel-java8-openj9-ubi

# Add config
COPY --chown=1001:0 pom/target/liberty/wlp/usr/servers/defaultServer/server.xml /config/
COPY --chown=1001:0 pom/target/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/liberty-plugin-variable-config.xml /config/configDropins/overrides/

# Add application
COPY --chown=1001:0 ear/target/guide-maven-multimodules-ear.ear /config/apps/
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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-ear</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>
</properties>

<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.0.2</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>
</plugins>
</build>

</project>
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:" + "9080" + "/" + 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,30 @@
<?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-jar</artifactId>
<version>1.0-SNAPSHOT</version>

<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>
</properties>

<dependencies>
<!-- For tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2017 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 io.openliberty.guides.multimodules.lib;

public class Converter {

public static int getFeet(int cm) {
int feet = (int) (cm / 30.48);
return feet;
}

public static int getInches(int cm) {
double feet = cm / 30.48;
int inches = (int) (cm / 2.54) - ((int) feet * 12);
return inches;
}

public static int sum(int a, int b) {
return a + b;
}

public static int diff(int a, int b) {
return a - b;
}

public static int product(int a, int b) {
return a * b;
}

public static int quotient(int a, int b) {
return a / b;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.openliberty.guides.multimodules.lib;

import org.junit.jupiter.api.Test;

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

public class ConverterUnitTest {

@Test
public void testHeightFeet() {
int feet = Converter.getFeet(61);
assertEquals(2, feet);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>jar</module>
<module>war</module>
<module>ear</module>
<module>pom</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>liberty-assembly</packaging>

<properties>
<!-- Liberty configuration -->
<liberty.var.default.http.port>9080</liberty.var.default.http.port>
<liberty.var.default.https.port>9443</liberty.var.default.https.port>
</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>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-ear</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ear</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>

<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>SUB_VERSION</version>
<extensions>true</extensions>
<configuration>
<looseApplication>true</looseApplication>
<deployPackages>all</deployPackages>
</configuration>
</plugin>

<!-- Since the package type is liberty-assembly,
need to run testCompile to compile the tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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>2.22.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,15 @@
<server description="Sample Liberty server">

<!--replaceable-->

<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-ear"
location="guide-maven-multimodules-ear.ear"
name="guide-maven-multimodules-ear" />

</server>
Loading

0 comments on commit 5a78c99

Please sign in to comment.