@@ -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) does not yet depend on core module — only GET / available.
302+ // Cloud profile activation verified via build logs for SB3.
303+ // TODO: Update SB3 assertions once cloudfoundry/java-test-applications adds core to boot3 module.
304+ context ("with real Spring Boot fat jars: java-cfenv injection" , func () {
305+ it ("SB3 (Spring Boot 3.x) -- java-cfenv 3.x, cloud profile via logs" , func () {
306+ if sb3JarPath == "" {
307+ t .Skip ("SB3 jar not available" )
308+ }
309+ deployment , logs , err := platform .Deploy .
310+ WithServices (map [string ]switchblade.Service {
311+ "db" : {"uri" : "postgres://host:5432/dbname" },
312+ }).
313+ WithEnv (map [string ]string {
314+ "BP_JAVA_VERSION" : "17" ,
315+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
316+ }).
317+ Execute (name , sb3JarPath )
318+ Expect (err ).NotTo (HaveOccurred (), logs .String )
319+
320+ // Buildpack detected and injected correct java-cfenv 3.x
321+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
322+ Expect (logs .String ()).To (ContainSubstring ("3." ))
323+
324+ // java-cfenv activated "cloud" profile — verified via Spring Boot startup log
325+ // (SB3 jar doesn't expose /active-profiles endpoint yet)
326+ // Use Eventually: RuntimeLogs() may be called before Spring Boot finishes starting.
327+ Eventually (func () (string , error ) {
328+ return deployment .RuntimeLogs ()
329+ }).Should (ContainSubstring (`profile is active: "cloud"` ))
330+
331+ // App is live
332+ Eventually (deployment ).Should (matchers .Serve (ContainSubstring ("ok" )).WithEndpoint ("/" ))
333+ })
334+
335+ it ("SB4 (Spring Boot 4.x) -- java-cfenv 4.x, cloud profile, loaded-jars, vcap mapping" , func () {
336+ if sb4JarPath == "" {
337+ t .Skip ("SB4 jar not available" )
338+ }
339+ deployment , logs , err := platform .Deploy .
340+ WithServices (map [string ]switchblade.Service {
341+ "db" : {"uri" : "postgres://host:5432/dbname" },
342+ }).
343+ WithEnv (map [string ]string {
344+ "BP_JAVA_VERSION" : "21" ,
345+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
346+ }).
347+ Execute (name , sb4JarPath )
348+ Expect (err ).NotTo (HaveOccurred (), logs .String )
349+
350+ // Buildpack detected and injected correct java-cfenv 4.x
351+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
352+ Expect (logs .String ()).To (ContainSubstring ("4." ))
353+
354+ // java-cfenv activated "cloud" profile — direct endpoint assertion
355+ Eventually (deployment ).Should (matchers .Serve (
356+ ContainSubstring ("cloud" )).WithEndpoint ("/active-profiles" ))
357+
358+ // java-cfenv jar loaded by JarLauncher via BOOT-INF/lib symlink — visible in /loaded-jars
359+ // (unlike /class-path which only shows JVM system classpath)
360+ Eventually (deployment ).Should (matchers .Serve (
361+ ContainSubstring ("java-cfenv" )).WithEndpoint ("/loaded-jars" ))
362+ })
363+
364+ it ("SB4 (Spring Boot 4.x) -- java-cfenv 4.x, container-security-provider, cf-metrics-exporter" , func () {
365+ if sb4JarPath == "" {
366+ t .Skip ("SB4 jar not available" )
367+ }
368+ deployment , logs , err := platform .Deploy .
369+ WithServices (map [string ]switchblade.Service {
370+ "db" : {"uri" : "postgres://host:5432/dbname" },
371+ }).
372+ WithEnv (map [string ]string {
373+ "BP_JAVA_VERSION" : "21" ,
374+ "JBP_CONFIG_JAVA_CF_ENV" : "{enabled: true}" ,
375+ // cf-metrics-exporter: rpsType=random + enableLogEmitter requires no external infra
376+ "CF_METRICS_EXPORTER_ENABLED" : "true" ,
377+ "CF_METRICS_EXPORTER_PROPS" : "rpsType=random,enableLogEmitter" ,
378+ }).
379+ Execute (name , sb4JarPath )
380+ Expect (err ).NotTo (HaveOccurred (), logs .String )
381+
382+ // java-cfenv: correct 4.x version detected and injected
383+ Expect (logs .String ()).To (ContainSubstring ("Java CF Env" ))
384+ Expect (logs .String ()).To (ContainSubstring ("4." ))
385+
386+ // cf-metrics-exporter: -javaagent present in JVM input arguments
387+ Expect (logs .String ()).To (ContainSubstring ("CF Metrics Exporter" ))
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