Skip to content

Commit 5355c2f

Browse files
committed
Fixed failing Integration tests
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 69c2067 commit 5355c2f

File tree

64 files changed

+1902
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1902
-39
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ repositories {
2929
mavenLocal()
3030
}
3131

32+
java {
33+
sourceCompatibility = JavaVersion.VERSION_17
34+
targetCompatibility = JavaVersion.VERSION_17
35+
}
3236

3337
if (project.hasProperty('mainClass')) {
3438
mainClassName = project.getProperty('mainClass')

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
version=1.0.11
1+
version=1.1.0
2+

src/test/java/com/ibm/cldk/CodeAnalyzerIntegrationTest.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CodeAnalyzerIntegrationTest {
2727
* Creates a Java 11 test container that mounts the build/libs folder.
2828
*/
2929
static String codeanalyzerVersion;
30+
static final String javaVersion = "17";
3031

3132
static {
3233
// Build project first
@@ -43,7 +44,7 @@ public class CodeAnalyzerIntegrationTest {
4344
}
4445

4546
@Container
46-
static final GenericContainer<?> container = new GenericContainer<>("openjdk:11-jdk")
47+
static final GenericContainer<?> container = new GenericContainer<>("openjdk:17-jdk")
4748
.withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh"))
4849
.withCommand("-c", "while true; do sleep 1; done")
4950
.withFileSystemBind(
@@ -76,9 +77,11 @@ static void setUp() {
7677
}
7778

7879
@Test
79-
void shouldHaveJava11Installed() throws Exception {
80-
var result = container.execInContainer("java", "-version");
81-
Assertions.assertTrue(result.getStderr().contains("openjdk version \"11"));
80+
void shouldHaveCorrectJavaVersionInstalled() throws Exception {
81+
var baseContainerresult = container.execInContainer("java", "-version");
82+
var mvnContainerresult = mavenContainer.execInContainer("java", "-version");
83+
Assertions.assertTrue(baseContainerresult.getStderr().contains("openjdk version \"" + javaVersion), "Base container Java version should be " + javaVersion);
84+
Assertions.assertTrue(mvnContainerresult.getStderr().contains("openjdk version \"" + javaVersion), "Maven container Java version should be " + javaVersion);
8285
}
8386

8487
@Test
@@ -112,38 +115,34 @@ void corruptMavenShouldNotBuildWithWrapper() throws IOException, InterruptedExce
112115
Assertions.assertNotEquals(0, mavenProjectBuildWithWrapper.getExitCode());
113116
}
114117

115-
// @Test
116-
// void corruptMavenShouldProduceAnalysisArtifactsWhenMVNCommandIsInPath() throws IOException, InterruptedException {
117-
// // Let's start by building the project by itself
118-
// var corruptMavenProjectBuild = mavenContainer.withWorkingDirectory("/test-applications/mvnw-corrupt-test").execInContainer("mvn", "-f", "/test-applications/mvnw-corrupt-test/pom.xml", "clean", "compile");
119-
// Assertions.assertEquals(0, corruptMavenProjectBuild.getExitCode(), "Failed to build the project with system's default Maven.");
120-
// // NOw run codeanalyzer and assert if analysis.json is generated.
121-
// mavenContainer.execInContainer("java", "-jar", String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion), "--input=/test-applications/mvnw-corrupt-test", "--output=/tmp/", "--analysis-level=2", "--no-build");
122-
// var codeAnalyzerOutputDirContents = mavenContainer.execInContainer("ls", "/tmp/analysis.json");
123-
// String codeAnalyzerOutputDirContentsStdOut = codeAnalyzerOutputDirContents.getStdout();
124-
// Assertions.assertTrue(codeAnalyzerOutputDirContentsStdOut.length() > 0, "Could not find 'analysis.json'.");
125-
// Assertions.assertTrue(codeAnalyzerOutputDirContentsStdOut.contains("Building the project using") && codeAnalyzerOutputDirContentsStdOut.contains("/mvn."));
126-
// Assertions.assertFalse(codeAnalyzerOutputDirContentsStdOut.contains("Building the project using") && codeAnalyzerOutputDirContentsStdOut.contains("/test-applications/mvnw-corrupt-test/mvnw."));
127-
// }
128-
//
129-
// @Test
130-
// void corruptMavenShouldNotTerminateWithErrorWhenMavenIsNotPresentUnlessAnalysisLevel2() throws IOException, InterruptedException {
131-
// // When analysis level 2, we should get a Runtime Exception
132-
// assertThrows(RuntimeException.class, () ->
133-
// container.execInContainer(
134-
// "java",
135-
// "-jar",
136-
// String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
137-
// "--input=/test-applications/mvnw-corrupt-test",
138-
// "--output=/tmp/",
139-
// "--analysis-level=2"
140-
// )
141-
// );
142-
// // When analysis level is 1, we should still be able to generate an analysis.json file.
143-
// container.execInContainer("java", "-jar", String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion), "--input=/test-applications/mvnw-corrupt-test", "--output=/tmp/", "--analysis-level=1");
144-
// var codeAnalyzerOutputDirContents = container.execInContainer("ls", "/tmp/analysis.json");
145-
// String codeAnalyzerOutputDirContentsStdOut = codeAnalyzerOutputDirContents.getStdout();
146-
// Assertions.assertTrue(codeAnalyzerOutputDirContentsStdOut.length() > 0, "Could not find 'analysis.json'.");
147-
// Assertions.assertTrue(codeAnalyzerOutputDirContentsStdOut.contains("Could not find Maven or a valid Maven Wrapper"));
148-
// }
118+
@Test
119+
void corruptMavenShouldProduceAnalysisArtifactsWhenMVNCommandIsInPath() throws IOException, InterruptedException {
120+
// Let's start by building the project by itself
121+
var corruptMavenProjectBuild = mavenContainer.withWorkingDirectory("/test-applications/mvnw-corrupt-test").execInContainer("mvn", "-f", "/test-applications/mvnw-corrupt-test/pom.xml", "clean", "compile");
122+
Assertions.assertEquals(0, corruptMavenProjectBuild.getExitCode(), "Failed to build the project with system's default Maven.");
123+
// NOw run codeanalyzer and assert if analysis.json is generated.
124+
var runCodeAnalyzer = mavenContainer.execInContainer("java", "-jar", String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion), "--input=/test-applications/mvnw-corrupt-test", "--output=/tmp/", "--analysis-level=2", "--verbose", "--no-build");
125+
var codeAnalyzerOutputDirContents = mavenContainer.execInContainer("ls", "/tmp/analysis.json");
126+
String codeAnalyzerOutputDirContentsStdOut = codeAnalyzerOutputDirContents.getStdout();
127+
Assertions.assertTrue(codeAnalyzerOutputDirContentsStdOut.length() > 0, "Could not find 'analysis.json'.");
128+
// mvnw is corrupt, so we should see an error message in the output.
129+
Assertions.assertTrue(runCodeAnalyzer.getStdout().contains("[ERROR]\tCannot run program \"/test-applications/mvnw-corrupt-test/mvnw\"") && runCodeAnalyzer.getStdout().contains("/mvn."));
130+
// We should correctly identify the build tool used in the mvn command from the system path.
131+
Assertions.assertTrue(runCodeAnalyzer.getStdout().contains("[INFO]\tBuilding the project using /usr/bin/mvn."));
132+
}
133+
134+
@Test
135+
void corruptMavenShouldNotTerminateWithErrorWhenMavenIsNotPresentUnlessAnalysisLevel2() throws IOException, InterruptedException {
136+
// When analysis level 2, we should get a Runtime Exception
137+
var runCodeAnalyzer = container.execInContainer(
138+
"java",
139+
"-jar",
140+
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
141+
"--input=/test-applications/mvnw-corrupt-test",
142+
"--output=/tmp/",
143+
"--analysis-level=2"
144+
);
145+
Assertions.assertEquals(1, runCodeAnalyzer.getExitCode());
146+
Assertions.assertTrue(runCodeAnalyzer.getStderr().contains("java.lang.RuntimeException"));
147+
}
149148
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.ear
17+
*.zip
18+
*.tar.gz
19+
*.rar
20+
21+
# Don't ignore jar files in any level of binary and dependencies
22+
!**/binaries/**/*.jar
23+
!**/libs/**/*.jar
24+
25+
# virtual machine crash logs
26+
hs_err_pid*
27+
28+
# Ignore Gradle files
29+
.gradle/
30+
build/
31+
32+
# Ignore Maven target folder
33+
target/
34+
35+
# Ignore IntelliJ IDEA files
36+
.idea/
37+
*.iml
38+
*.iws
39+
*.ipr
40+
41+
# Ignore Eclipse files
42+
.settings/
43+
*.classpath
44+
*.project
45+
46+
# Ignore VS Code files
47+
.vscode/
48+
49+
# Ignore everything in codeql-db except the directory itself
50+
codeql-db/*
51+
!codeql-db/.keep
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
!target/*.war
3+
!target/liberty/wlp/usr/shared/resources/*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
11+
.mvn/wrapper/maven-wrapper.jar
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
FROM icr.io/appcafe/open-liberty:kernel-slim-java17-openj9-ubi
3+
4+
COPY --chown=1001:0 /src/main/liberty/config /config
5+
6+
RUN features.sh
7+
8+
COPY --chown=1001:0 target/*.war /config/apps
9+
10+
RUN configure.sh
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
After you generate a starter project, these instructions will help you with what to do next.
2+
3+
The Open Liberty starter gives you a simple, quick way to get the necessary files to start building
4+
an application on Open Liberty. There is no need to search how to find out what to add to your
5+
Maven build files. A simple RestApplication.java file is generated for you to start
6+
creating a REST based application. A server.xml configuration file is provided with the necessary
7+
features for the MicroProfile and Jakarta EE versions that you previously selected.
8+
9+
If you plan on developing and/or deploying your app in a containerized environment, the included
10+
Dockerfile will make it easier to create your application image on top of the Open Liberty Docker
11+
image.
12+
13+
1) Once you download the starter project, unpackage the .zip file on your machine.
14+
2) Open a command line session, navigate to the installation directory, and run `./mvnw liberty:dev` (Linux/Mac) or `mvnw liberty:dev` (Windows).
15+
This will install all required dependencies and start the default server. When complete, you will
16+
see the necessary features installed and the message "server is ready to run a smarter planet."
17+
18+
For information on developing your application in dev mode using Maven, see the
19+
dev mode documentation (https://openliberty.io/docs/latest/development-mode.html).
20+
21+
For further help on getting started actually developing your application, see some of our
22+
MicroProfile guides (https://openliberty.io/guides/?search=microprofile&key=tag) and Jakarta EE
23+
guides (https://openliberty.io/guides/?search=jakarta%20ee&key=tag).
24+
25+
If you have problems building the starter project, make sure the Java SE version on your
26+
machine matches the Java SE version you picked from the Open Liberty starter on the downloads
27+
page (https://openliberty.io/downloads/). You can test this with the command `java -version`.
28+
29+
Open Liberty performs at its best when running using Open J9 which can be obtained via IBM Semeru
30+
(https://developer.ibm.com/languages/java/semeru-runtimes/downloads/). For a full list of supported
31+
Java SE versions and where to obtain them, reference the Java SE support page
32+
(https://openliberty.io/docs/latest/java-se.html).
33+
34+
If you find any issues with the starter project or have recommendations to improve it, open an
35+
issue in the starter GitHub repo (https://github.com/OpenLiberty/start.openliberty.io).
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
id 'java'
7+
id 'maven-publish'
8+
}
9+
10+
repositories {
11+
mavenLocal()
12+
maven {
13+
url = uri('https://repo.maven.apache.org/maven2/')
14+
}
15+
}
16+
17+
dependencies {
18+
compileOnly 'javax:javaee-api:7.0'
19+
compileOnly 'org.eclipse.microprofile:microprofile:1.4'
20+
}
21+
22+
group = 'com.demo'
23+
version = '1.0-SNAPSHOT'
24+
description = 'my-javaee-mvn'
25+
java.sourceCompatibility = JavaVersion.VERSION_1_8
26+
27+
publishing {
28+
publications {
29+
maven(MavenPublication) {
30+
from(components.java)
31+
}
32+
}
33+
}
34+
35+
tasks.withType(JavaCompile) {
36+
options.encoding = 'UTF-8'
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)