Skip to content

Commit 39a12b2

Browse files
committed
fix: improve integration test assertions for Java version verification
- Replace weak assertions that always passed (e.g., ContainSubstring("Tomcat")) - Add specific version checks (e.g., "Installing OpenJDK 17.") - Remove redundant JBP_CONFIG_OPEN_JDK_JRE when BP_JAVA_VERSION is set - Add dedicated tests for JBP_CONFIG_OPEN_JDK_JRE version selection These changes ensure tests actually validate the correct Java version is installed, preventing false positives.
1 parent 5cd9eec commit 39a12b2

4 files changed

Lines changed: 42 additions & 19 deletions

File tree

src/integration/dist_zip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func testDistZip(platform switchblade.Platform, fixtures string) func(*testing.T
7171
Expect(err).NotTo(HaveOccurred(), logs.String)
7272

7373
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
74-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
74+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 8."))
7575
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
7676
})
7777

@@ -84,7 +84,7 @@ func testDistZip(platform switchblade.Platform, fixtures string) func(*testing.T
8484
Expect(err).NotTo(HaveOccurred(), logs.String)
8585

8686
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
87-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
87+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
8888
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
8989
})
9090
})

src/integration/ratpack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func testRatpack(platform switchblade.Platform, fixtures string) func(*testing.T
7171
Expect(err).NotTo(HaveOccurred(), logs.String)
7272

7373
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
74-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
74+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
7575
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
7676
})
7777
})

src/integration/spring_boot_cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func testSpringBootCLI(platform switchblade.Platform, fixtures string) func(*tes
107107
Expect(err).NotTo(HaveOccurred(), logs.String)
108108

109109
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
110-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
110+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
111111
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
112112
})
113113
})

src/integration/tomcat_test.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
135135
Execute(name, filepath.Join(fixtures, "containers", "tomcat_javax"))
136136
Expect(err).NotTo(HaveOccurred(), logs.String)
137137

138-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
138+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 8."))
139139
Expect(logs.String()).To(ContainSubstring("Tomcat 9"))
140140
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
141141
})
@@ -148,7 +148,7 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
148148
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
149149
Expect(err).NotTo(HaveOccurred(), logs.String)
150150

151-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
151+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 11."))
152152
Expect(logs.String()).To(ContainSubstring("Tomcat 10"))
153153
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
154154
})
@@ -161,24 +161,24 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
161161
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
162162
Expect(err).NotTo(HaveOccurred(), logs.String)
163163

164-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
164+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
165165
Expect(logs.String()).To(ContainSubstring("Tomcat 10"))
166166
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
167167
})
168168
})
169169

170170
context("with memory limits", func() {
171-
it("respects memory calculator settings", func() {
171+
it("respects memory calculator settings with JAVA_OPTS", func() {
172172
deployment, logs, err := platform.Deploy.
173173
WithEnv(map[string]string{
174-
"BP_JAVA_VERSION": "11",
175-
"JAVA_OPTS": "-Xmx256m",
176-
"JBP_CONFIG_OPEN_JDK_JRE": "{jre: {version: 11.+}}",
174+
"BP_JAVA_VERSION": "11",
175+
"JAVA_OPTS": "-Xmx256m",
177176
}).
178177
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
179178

180179
Expect(err).NotTo(HaveOccurred(), logs.String)
181180

181+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 11."))
182182
Expect(logs.String()).To(ContainSubstring("memory"))
183183
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
184184
})
@@ -215,19 +215,14 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
215215
deployment, logs, err := platform.Deploy.
216216
WithBuildpacks("https://github.com/cloudfoundry/java-buildpack.git#feature/go-migration").
217217
WithEnv(map[string]string{
218-
"BP_JAVA_VERSION": "21",
219-
"JBP_CONFIG_OPEN_JDK_JRE": "{jre: {version: 21.+}}",
218+
"BP_JAVA_VERSION": "21",
220219
}).
221220
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
222221

223222
Expect(err).NotTo(HaveOccurred(), logs.String)
224223

225-
// Verify Java 21 is used
226-
Expect(logs.String()).To(ContainSubstring("OpenJDK"))
227-
Expect(logs.String()).To(Or(
228-
ContainSubstring("21."),
229-
ContainSubstring("Tomcat"),
230-
))
224+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 21."))
225+
Expect(logs.String()).To(ContainSubstring("Tomcat"))
231226

232227
// If deployment succeeds, it means:
233228
// 1. bin/detect succeeded (detected Tomcat)
@@ -239,6 +234,34 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
239234
})
240235
})
241236

237+
context("with JBP_CONFIG_OPEN_JDK_JRE version selection", func() {
238+
it("respects JBP_CONFIG_OPEN_JDK_JRE version pattern", func() {
239+
deployment, logs, err := platform.Deploy.
240+
WithEnv(map[string]string{
241+
"JBP_CONFIG_OPEN_JDK_JRE": "{jre: {version: 17.+}}",
242+
}).
243+
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
244+
245+
Expect(err).NotTo(HaveOccurred(), logs.String)
246+
247+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
248+
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
249+
})
250+
251+
it("respects JBP_CONFIG_OPEN_JDK_JRE over manifest default", func() {
252+
deployment, logs, err := platform.Deploy.
253+
WithEnv(map[string]string{
254+
"JBP_CONFIG_OPEN_JDK_JRE": "{jre: {version: 21.+}}",
255+
}).
256+
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
257+
258+
Expect(err).NotTo(HaveOccurred(), logs.String)
259+
260+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 21."))
261+
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
262+
})
263+
})
264+
242265
context("with external Tomcat configuration", func() {
243266
it("downloads and applies configuration from real repository", func() {
244267
// This test verifies the external configuration workflow:

0 commit comments

Comments
 (0)