@@ -11,7 +11,7 @@ import (
1111 . "github.com/onsi/gomega"
1212)
1313
14- func testSpringBoot (platform switchblade.Platform , fixtures string ) func (* testing.T , spec.G , spec.S ) {
14+ func testSpringBoot (platform switchblade.Platform , fixtures string , sb3JarPath , sb4JarPath string ) func (* testing.T , spec.G , spec.S ) {
1515 return func (t * testing.T , context spec.G , it spec.S ) {
1616 var (
1717 Expect = NewWithT (t ).Expect
@@ -290,5 +290,112 @@ func testSpringBoot(platform switchblade.Platform, fixtures string) func(*testin
290290 )).WithEndpoint ("/jvm-args" ))
291291 })
292292 })
293+
294+ // Tests using real Spring Boot fat jars from cloudfoundry/java-test-applications@v1.0.0.
295+ // SB4 (java-main-application) exposes RuntimeUtils endpoints (via core module):
296+ // GET /active-profiles -> ["cloud"] when java-cfenv activates cloud profile
297+ // GET /loaded-jars -> full classloader chain URLs incl. BOOT-INF/lib/*
298+ // GET /spring-env?key=<prop> -> Spring Environment property value
299+ // GET /environment-variables -> raw env vars
300+ // GET /input-arguments -> JVM input arguments (-javaagent etc.)
301+ // SB3 (java-main-application-boot3) only exposes GET / (no core module dependency).
302+ // Cloud profile activation verified via runtime logs for SB3.
303+ context ("with real Spring Boot fat jars: java-cfenv injection" , func () {
304+ it ("SB3 (Spring Boot 3.x) -- java-cfenv 3.x, cloud profile via logs" , func () {
305+ if sb3JarPath == "" {
306+ t .Skip ("SB3 jar not available" )
307+ }
308+ deployment , logs , err := platform .Deploy .
309+ WithServices (map [string ]switchblade.Service {
310+ "db" : {"uri" : "postgres://host:5432/dbname" },
311+ }).
312+ WithEnv (map [string ]string {
313+ "BP_JAVA_VERSION" : "17" ,
314+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
315+ }).
316+ Execute (name , sb3JarPath )
317+ Expect (err ).NotTo (HaveOccurred (), logs .String )
318+
319+ // Buildpack detected and injected correct java-cfenv 3.x
320+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
321+ Expect (logs .String ()).To (ContainSubstring ("3." ))
322+
323+ // java-cfenv activated "cloud" profile — verified via Spring Boot startup log
324+ // (SB3 jar doesn't expose /active-profiles endpoint yet)
325+ // Use Eventually: RuntimeLogs() may be called before Spring Boot finishes starting.
326+ Eventually (func () (string , error ) {
327+ return deployment .RuntimeLogs ()
328+ }).Should (ContainSubstring (`profile is active: "cloud"` ))
329+
330+ // App is live
331+ Eventually (deployment ).Should (matchers .Serve (ContainSubstring ("ok" )).WithEndpoint ("/" ))
332+ })
333+
334+ it ("SB4 (Spring Boot 4.x) -- java-cfenv 4.x, cloud profile, loaded-jars, vcap mapping" , func () {
335+ if sb4JarPath == "" {
336+ t .Skip ("SB4 jar not available" )
337+ }
338+ deployment , logs , err := platform .Deploy .
339+ WithServices (map [string ]switchblade.Service {
340+ "db" : {"uri" : "postgres://host:5432/dbname" },
341+ }).
342+ WithEnv (map [string ]string {
343+ "BP_JAVA_VERSION" : "21" ,
344+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
345+ }).
346+ Execute (name , sb4JarPath )
347+ Expect (err ).NotTo (HaveOccurred (), logs .String )
348+
349+ // Buildpack detected and injected correct java-cfenv 4.x
350+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
351+ Expect (logs .String ()).To (ContainSubstring ("4." ))
352+
353+ // java-cfenv activated "cloud" profile — direct endpoint assertion
354+ Eventually (deployment ).Should (matchers .Serve (
355+ ContainSubstring ("cloud" )).WithEndpoint ("/active-profiles" ))
356+
357+ // java-cfenv jar loaded by JarLauncher via BOOT-INF/lib symlink — visible in /loaded-jars
358+ // (unlike /class-path which only shows JVM system classpath)
359+ Eventually (deployment ).Should (matchers .Serve (
360+ ContainSubstring ("java-cfenv" )).WithEndpoint ("/loaded-jars" ))
361+ })
362+
363+ it ("SB4 (Spring Boot 4.x) -- java-cfenv 4.x, container-security-provider, cf-metrics-exporter" , func () {
364+ if sb4JarPath == "" {
365+ t .Skip ("SB4 jar not available" )
366+ }
367+ deployment , logs , err := platform .Deploy .
368+ WithServices (map [string ]switchblade.Service {
369+ "db" : {"uri" : "postgres://host:5432/dbname" },
370+ }).
371+ WithEnv (map [string ]string {
372+ "BP_JAVA_VERSION" : "21" ,
373+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
374+ // cf-metrics-exporter: rpsType=random + enableLogEmitter requires no external infra
375+ "CF_METRICS_EXPORTER_ENABLED" : "true" ,
376+ "CF_METRICS_EXPORTER_PROPS" : "rpsType=random,enableLogEmitter" ,
377+ }).
378+ Execute (name , sb4JarPath )
379+ Expect (err ).NotTo (HaveOccurred (), logs .String )
380+
381+ // java-cfenv: correct 4.x version detected and injected
382+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
383+ Expect (logs .String ()).To (ContainSubstring ("4." ))
384+
385+ // cf-metrics-exporter: -javaagent present in JVM input arguments
386+ Expect (logs .String ()).To (ContainSubstring ("CF Metrics Exporter" ))
387+ Expect (logs .String ()).To (ContainSubstring ("enabled, with properties: rpsType=random,enableLogEmitter" ))
388+ Eventually (deployment ).Should (matchers .Serve (
389+ ContainSubstring ("cf-metrics-exporter" )).WithEndpoint ("/input-arguments" ))
390+
391+ // container-security-provider: env var set at runtime
392+ Eventually (deployment ).Should (matchers .Serve (
393+ ContainSubstring ("CONTAINER_SECURITY_PROVIDER" )).WithEndpoint ("/environment-variables" ))
394+
395+ // java-cfenv activated "cloud" profile
396+ Eventually (deployment ).Should (matchers .Serve (
397+ ContainSubstring ("cloud" )).WithEndpoint ("/active-profiles" ))
398+ })
399+ })
293400 }
294- }
401+ }
0 commit comments