-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathframeworks_test.go
More file actions
986 lines (884 loc) · 37.7 KB
/
Copy pathframeworks_test.go
File metadata and controls
986 lines (884 loc) · 37.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
package integration_test
import (
"path/filepath"
"testing"
"github.com/cloudfoundry/switchblade"
"github.com/cloudfoundry/switchblade/matchers"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testFrameworks(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
name string
)
it.Before(func() {
var err error
name, err = switchblade.RandomName()
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
if t.Failed() && name != "" {
t.Logf("❌ FAILED TEST - App/Container: %s", name)
t.Logf(" Platform: %s", settings.Platform)
}
// Only attempt cleanup if test actually ran (not skipped) and name was set
if name != "" && !t.Skipped() && (!settings.KeepFailedContainers || !t.Failed()) {
Expect(platform.Delete.Execute(name)).To(Succeed())
}
})
context("APM Agents", func() {
context("with New Relic service binding", func() {
it("detects and installs New Relic agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"newrelic": {
"licenseKey": "test-license-key-1234567890abcdef",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify New Relic agent was detected
Expect(logs.String()).To(ContainSubstring("New Relic Agent"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures New Relic with license key from service binding", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-newrelic-service": {
"licenseKey": "abc123def456ghi789jkl012mno345pq",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("New Relic Agent"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with AppDynamics service binding", func() {
it("detects and installs AppDynamics agent", func() {
t.Skip("SKIPPED: AppDynamics agent requires authentication and is not in manifest.yml - agent must be provided via service binding or downloaded at runtime")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"appdynamics": {
"account-access-key": "test-access-key",
"account-name": "customer1",
"host-name": "appdynamics.example.com",
"port": "443",
"ssl-enabled": "true",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify AppDynamics agent was detected
Expect(logs.String()).To(ContainSubstring("AppDynamics Agent"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures AppDynamics with controller info from service binding", func() {
t.Skip("SKIPPED: AppDynamics agent requires authentication and is not in manifest.yml - agent must be provided via service binding or downloaded at runtime")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-appdynamics-service": {
"account-access-key": "xyz789",
"account-name": "production-account",
"host-name": "controller.appdynamics.example.com",
"port": "8090",
"ssl-enabled": "false",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("AppDynamics Agent"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Dynatrace service binding", func() {
it("detects and installs Dynatrace agent", func() {
t.Skip("Dynatrace agent downloads from API at runtime and requires valid credentials - this test cannot run with fake credentials")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"dynatrace": {
"environmentid": "abc12345",
"apitoken": "test-api-token-xyz",
"apiurl": "https://abc12345.live.dynatrace.com/api",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify Dynatrace agent was detected and installed
Expect(logs.String()).To(ContainSubstring("Dynatrace"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures Dynatrace with environment ID from service binding", func() {
t.Skip("Dynatrace agent downloads from API at runtime and requires valid credentials - this test cannot run with fake credentials")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-dynatrace-service": {
"environmentid": "xyz78901",
"apitoken": "dt0c01.XXXXXXXXX.YYYYYYYYYYYY",
"apiurl": "https://xyz78901.live.dynatrace.com/api",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Dynatrace"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with multiple APM agents", func() {
it("can handle multiple agent service bindings", func() {
t.Skip("Test uses AppDynamics which requires authentication and is not in manifest - skipping until test is updated to use agents that work without auth")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"newrelic": {
"licenseKey": "test-license-key",
},
"appdynamics": {
"account-access-key": "test-key",
"account-name": "test-account",
"host-name": "controller.appdynamics.com",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Both agents should be detected
Expect(logs.String()).To(Or(
ContainSubstring("New Relic Agent"),
ContainSubstring("AppDynamics Agent"),
))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Azure Application Insights service binding", func() {
it("detects and installs Azure Application Insights agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"azure-application-insights": {
"connection_string": "InstrumentationKey=12345678-1234-1234-1234-123456789abc;IngestionEndpoint=https://eastus-1.in.applicationinsights.azure.com/",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Azure Application Insights"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures Azure Application Insights with instrumentation key", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-app-insights": {
"instrumentation_key": "87654321-4321-4321-4321-cba987654321",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Azure Application Insights"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with SkyWalking service binding", func() {
it("detects and installs SkyWalking agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"skywalking": {
"oap_server": "skywalking.example.com:11800",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("SkyWalking"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures SkyWalking with OAP server address", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-skywalking": {
"oap_server": "oap.skywalking.prod:11800",
"service_name": "my-java-app",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("SkyWalking"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Splunk OTEL service binding", func() {
it("detects and installs Splunk OTEL Java agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"splunk-otel": {
"access_token": "test-splunk-token-xyz123",
"realm": "us0",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Splunk OTEL"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures Splunk OTEL with realm and access token", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-splunk-otel": {
"access_token": "ABC123XYZ789",
"realm": "eu0",
"endpoint": "https://ingest.eu0.signalfx.com",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Splunk OTEL"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Google Stackdriver Profiler service binding", func() {
it("detects and installs Google Stackdriver Profiler", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"google-stackdriver-profiler": {
"project_id": "my-gcp-project-123456",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Google Stackdriver Profiler"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Datadog service binding", func() {
it("detects and installs Datadog Javaagent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"datadog": {
"api_key": "test-datadog-api-key-xyz",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Datadog"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures Datadog with API key from service binding", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-datadog-service": {
"api_key": "dd-api-key-123abc456def",
"site": "datadoghq.eu",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Datadog"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Elastic APM service binding", func() {
it("detects and installs Elastic APM agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"elastic-apm": {
"server_url": "https://apm.elastic.example.com:8200",
"secret_token": "test-elastic-token",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Elastic APM"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures Elastic APM with server URL and token", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-elastic-apm": {
"server_url": "https://apm.production.example.com:8200",
"secret_token": "elastic-secret-xyz123",
"service_name": "my-java-app",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Elastic APM"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with OpenTelemetry service binding", func() {
it("detects and installs OpenTelemetry Javaagent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"otel-collector": {
"otel.exporter.otlp.endpoint": "http://otel-collector:4317",
"otel.service.name": "my-test-app",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("OpenTelemetry"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("configures OpenTelemetry with OTLP endpoint from service binding", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"my-otel-service": {
"otel.exporter.otlp.endpoint": "https://otel.example.com:4318",
"otel.traces.exporter": "otlp",
"otel.metrics.exporter": "otlp",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("OpenTelemetry"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Checkmarx IAST service binding", func() {
it("detects Checkmarx IAST service binding", func() {
t.Skip("Checkmarx IAST agent downloads from API at runtime and requires valid credentials - this test cannot run with fake credentials")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"checkmarx-iast": {
"url": "https://github.com/cloudfoundry/java-test-applications/releases/download/v1.0.0/java-main-application-1.0.0.jar",
"manager_url": "https://checkmarx.example.com",
"api_key": "test-api-key-12345",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify Checkmarx IAST framework was detected (even if download succeeds)
// Note: Using a real downloadable URL for testing
Expect(logs.String()).To(ContainSubstring("Checkmarx IAST"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("without APM service bindings", func() {
it("does not install any APM agents", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// No APM agents should be mentioned
Expect(logs.String()).NotTo(ContainSubstring("New Relic Agent"))
Expect(logs.String()).NotTo(ContainSubstring("AppDynamics Agent"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("JDBC Drivers", func() {
context("with PostgreSQL service binding", func() {
it("detects and installs PostgreSQL JDBC driver", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"postgres": {
"uri": "postgres://user:password@localhost:5432/mydb",
"username": "testuser",
"password": "testpass",
"hostname": "postgres.example.com",
"port": "5432",
"name": "mydb",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("PostgreSQL JDBC"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with MariaDB service binding", func() {
it("detects and installs MariaDB JDBC driver", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"mariadb": {
"uri": "mysql://user:password@localhost:3306/mydb",
"username": "testuser",
"password": "testpass",
"hostname": "mariadb.example.com",
"port": "3306",
"name": "mydb",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("MariaDB JDBC"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("mTLS Support", func() {
context("with Client Certificate Mapper enabled", func() {
it("detects and installs Client Certificate Mapper for mTLS support", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_CLIENT_CERTIFICATE_MAPPER": "{ enabled: true }",
}).
Execute(name, filepath.Join(fixtures, "containers", "tomcat"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Client Certificate Mapper should be detected and installed
Expect(logs.String()).To(ContainSubstring("Client Certificate Mapper"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("skips Client Certificate Mapper when disabled", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_CLIENT_CERTIFICATE_MAPPER": "{ enabled: false }",
}).
Execute(name, filepath.Join(fixtures, "containers", "tomcat"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Should not install when explicitly disabled
Expect(logs.String()).NotTo(ContainSubstring("Client Certificate Mapper"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Utility Frameworks", func() {
context("with Debug enabled", func() {
it("configures remote debugging via JDWP", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"BPL_DEBUG_ENABLED": "true",
"BPL_DEBUG_PORT": "8000",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Debug"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with JMX enabled", func() {
it("configures remote JMX monitoring", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"BPL_JMX_ENABLED": "true",
"BPL_JMX_PORT": "5000",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("JMX"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with CF Metrics Exporter enabled", func() {
it("detects and enables CF Metrics Exporter", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"CF_METRICS_EXPORTER_ENABLED": "true",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Log should indicate exporter enabled with version
Expect(logs.String()).To(ContainSubstring("CF Metrics Exporter v"))
Expect(logs.String()).To(ContainSubstring("enabled"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("log includes properties when provided", func() {
props := "debug,enableLogEmitter,intervalSeconds=30"
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"CF_METRICS_EXPORTER_ENABLED": "true",
"CF_METRICS_EXPORTER_PROPS": props,
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Should still show exporter enabled
Expect(logs.String()).To(ContainSubstring("CF Metrics Exporter v"))
Expect(logs.String()).To(ContainSubstring("enabled"))
// And include provided properties in logs/configuration output
Expect(logs.String()).To(Or(
ContainSubstring("CF_METRICS_EXPORTER_PROPS"),
ContainSubstring(props),
))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Testing & Code Coverage", func() {
context("with JaCoCo service binding", func() {
it("detects and installs JaCoCo agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"jacoco": {
"address": "localhost",
"port": "6300",
"output": "file", // Use file output instead of tcpclient to avoid network dependency
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("JaCoCo"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Spring Configuration", func() {
context("with Spring Auto-reconfiguration", func() {
it("detects and installs Spring Auto-reconfiguration for Spring apps", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"postgres": {
"uri": "postgres://user:password@localhost:5432/mydb",
"username": "testuser",
"password": "testpass",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JAVA_CF_ENV": "'{enabled: false}'",
"JBP_CONFIG_SPRING_AUTO_RECONFIGURATION": "'{enabled: true}'",
}).
Execute(name, filepath.Join(fixtures, "frameworks", "auto_reconfiguration_servlet_3"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Spring Auto-reconfiguration should be detected for Spring apps with services
Expect(logs.String()).To(ContainSubstring("Spring Auto-reconfiguration"))
// Spring Auto-reconfiguration should only be provided in the absence of Java Cf Env
Expect(logs.String()).NotTo(ContainSubstring("Java CF Env"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("skips Spring Auto-reconfiguration when disabled", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"postgres": {
"uri": "postgres://user:password@localhost:5432/mydb",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_SPRING_AUTO_RECONFIGURATION": "'{enabled: false}'",
}).
Execute(name, filepath.Join(fixtures, "frameworks", "auto_reconfiguration_servlet_3"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java Cf Env should be provided as it is enabled by default for Spring3 apps
Expect(logs.String()).To(ContainSubstring("Java CF Env"))
// Should not install when explicitly disabled
Expect(logs.String()).NotTo(ContainSubstring("Spring Auto-reconfiguration"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Java CF Env", func() {
it("detects and installs Java CF Env for Spring Boot 3.x apps", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"postgres": {
"uri": "postgres://user:password@localhost:5432/mydb",
"username": "testuser",
"password": "testpass",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "17",
"JBP_CONFIG_JAVA_CF_ENV": "'{enabled: true}'",
}).
Execute(name, filepath.Join(fixtures, "frameworks", "java_cf_boot_3"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java CF Env should be detected for Spring Boot 3.x apps
Expect(logs.String()).To(ContainSubstring("Java CF Env"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("JVM Configuration", func() {
context("with Java Opts Framework", func() {
it("applies custom JAVA_OPTS from environment", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
// Reduce code cache and thread stack to fit within 1G memory limit (v4 calculator)
"JAVA_OPTS": "-Xmx384m -XX:ReservedCodeCacheSize=120M -Xss512k -Dcustom.property=test",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java Opts framework should detect JAVA_OPTS environment variable
Expect(logs.String()).To(ContainSubstring("Java Opts"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("applies custom JAVA_OPTS from configuration file", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
// Reduce heap and code cache to fit within 1G memory limit (v4 calculator)
"JBP_CONFIG_JAVA_OPTS": "'{java_opts: [\"-Xms256m\", \"-Xmx384m\", \"-XX:ReservedCodeCacheSize=120M\", \"-Xss512k\"]}'",
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java Opts framework should detect configuration
Expect(logs.String()).To(ContainSubstring("Java Opts"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("handles quoted strings with spaces in JAVA_OPTS", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JAVA_OPTS": `'java_opts: -DtestJBPConfig1=''test test'' -DtestJBPConfig2="value with spaces"'`,
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java Opts framework should detect configuration
Expect(logs.String()).To(ContainSubstring("Java Opts"))
// Should properly handle quoted strings with spaces
Expect(logs.String()).To(ContainSubstring("Adding configured JAVA_OPTS"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("expands environment variables in JAVA_OPTS at runtime", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"TEST_ENV_VAR": "test-value-123",
"JBP_CONFIG_JAVA_OPTS": `'java_opts: -DtestEnvVar="$TEST_ENV_VAR" -DtestPath="$PATH"'`,
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Java Opts framework should detect configuration
Expect(logs.String()).To(ContainSubstring("Java Opts"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
it("handles complex scenario with quotes and env vars like Ruby buildpack", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JAVA_OPTS": `'java_opts: -DtestJBPConfig1=''test test'' -DtestJBPConfig2="$PATH"'`,
}).
Execute(name, filepath.Join(fixtures, "apps", "integration_valid"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// This test verifies the fix for the Ruby vs Go buildpack parity issue
// Ruby buildpack correctly handled:
// - Single quotes with spaces: -DtestJBPConfig1='test test' -> -DtestJBPConfig1=test test
// - Environment variable expansion: -DtestJBPConfig2="$PATH" -> -DtestJBPConfig2=/usr/local/bin:/usr/bin:/bin
Expect(logs.String()).To(ContainSubstring("Java Opts"))
Expect(logs.String()).To(ContainSubstring("Adding configured JAVA_OPTS"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Development Tools", func() {
context("with JRebel Agent", func() {
it("detects and installs JRebel agent when rebel-remote.xml present", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JREBEL_AGENT": "'{enabled: true}'",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_multi_framework"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// JRebel agent should be detected when enabled
Expect(logs.String()).To(ContainSubstring("JRebel"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with YourKit Profiler", func() {
it("detects and installs YourKit profiler when enabled", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_YOUR_KIT_PROFILER": "'{enabled: true}'",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// YourKit profiler should be detected when enabled
Expect(logs.String()).To(ContainSubstring("YourKit"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with JProfiler Profiler", func() {
it("detects and installs JProfiler profiler when enabled", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JPROFILER_PROFILER": "{ enabled: true }",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// JProfiler profiler should be detected when enabled
Expect(logs.String()).To(ContainSubstring("JProfiler"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Specialized APM Agents", func() {
context("with Contrast Security service binding", func() {
it("detects and installs Contrast Security agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"contrast-security": {
"api_key": "test-api-key",
"service_key": "test-service-key",
"teamserver_url": "https://contrast.example.com",
"username": "agent@example.com",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Contrast Security"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Sealights service binding", func() {
it("detects and installs Sealights agent", func() {
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"sealights": {
"token": "test-token",
"lab_id": "test-lab-id",
"bs_id": "test-bs-id",
"proxy_url": "https://sealights.example.com",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Sealights"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Introscope service binding", func() {
it("detects and installs Introscope agent", func() {
t.Skip("SKIPPED: Introscope agent requires authentication and is not in manifest.yml")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"introscope": {
"agent_manager_url": "introscope.example.com:5001",
"agent_name": "test-agent",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Introscope"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Riverbed AppInternals service binding", func() {
it("detects and installs Riverbed AppInternals agent", func() {
t.Skip("SKIPPED: Riverbed agent downloads from service broker at runtime (v10.20+) and is not in manifest.yml")
deployment, logs, err := platform.Deploy.
WithServices(map[string]switchblade.Service{
"riverbed-appinternals": {
"analysis_server": "appinternals.example.com:4144",
"agent_name": "test-agent",
},
}).
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Riverbed AppInternals"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
context("Advanced Tooling", func() {
context("with AspectJ Weaver", func() {
it("detects and installs AspectJ Weaver when enabled", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_ASPECTJ_WEAVER_AGENT": "{ enabled: true }",
}).
Execute(name, filepath.Join(fixtures, "frameworks", "aspectj_weaver_meta_inf"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// AspectJ Weaver should be detected when enabled
Expect(logs.String()).To(ContainSubstring("AspectJ"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
context("with Container Security Provider", func() {
it("detects and configures Container Security Provider", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
Expect(err).NotTo(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Container Security Provider"))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
})
})
})
}
}