Repository navigation
Expand file tree
/
Copy pathjava_main_test.go
More file actions
128 lines (110 loc) · 4.65 KB
/
Copy pathjava_main_test.go
File metadata and controls
128 lines (110 loc) · 4.65 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
package integration_test
import (
"path/filepath"
"testing"
"github.com/cloudfoundry/switchblade"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testJavaMain(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() {
cleanupDeployedApp(t, platform, name)
})
context("with a Java Main application", func() {
it("detects application with Main-Class manifest entry", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
}).
Execute(name, filepath.Join(fixtures, "containers", "main"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify buildpack detects Java Main container from MANIFEST.MF
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
Expect(logs.String()).To(ContainSubstring("Java Main"))
})
})
context("with explicit main class", func() {
it("detects and configures the specified main class", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JAVA_MAIN": `{java_main_class: "io.pivotal.SimpleJava"}`,
}).
Execute(name, filepath.Join(fixtures, "containers", "main"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify buildpack detects and applies explicit main class configuration
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
Expect(logs.String()).To(ContainSubstring("Java Main"))
// NOTE: this test does NOT verify that java_main_class actually overrides the
// manifest Main-Class, because:
// 1. The fixture's MANIFEST.MF already has Main-Class: io.pivotal.SimpleJava
// (same value as JBP_CONFIG_JAVA_MAIN), so the test passes even if the
// config is ignored.
// 2. switchblade's Deployment struct does not expose the release command,
// so we cannot assert -cp vs -jar or which class was used.
// The override behaviour and -cp mode are covered by unit tests in
// src/java/containers/java_main_test.go.
})
})
context("with custom arguments", func() {
it("successfully stages with custom arguments", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
"JBP_CONFIG_JAVA_MAIN": `{arguments: "--server.port=$PORT"}`,
}).
Execute(name, filepath.Join(fixtures, "containers", "main"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify buildpack stages successfully with custom arguments
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
Expect(logs.String()).To(ContainSubstring("Java Main"))
// Verify app can start (validates command with arguments is valid)
Eventually(deployment.ExternalURL).ShouldNot(BeEmpty())
// NOTE: does not verify arguments are actually appended to the command line;
// that is covered by unit tests in src/java/containers/java_main_test.go.
})
})
context("with JAVA_OPTS", func() {
it("detects application with custom Java options", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"BP_JAVA_VERSION": "11",
// Reduce memory settings to fit within 1G limit (v4 calculator)
"JAVA_OPTS": "-Xmx384m -XX:ReservedCodeCacheSize=120M -Xss512k -XX:+UseG1GC",
}).
Execute(name, filepath.Join(fixtures, "containers", "main"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify buildpack stages successfully with JAVA_OPTS
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
Expect(logs.String()).To(ContainSubstring("Java Main"))
// NOTE: does not verify JAVA_OPTS are applied to the JVM command line;
// staging success only confirms the options did not break the build.
})
})
context("with JRE vendor selection", func() {
it("deploys with SAPMachine JRE from manifest", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"JBP_CONFIG_SAP_MACHINE_JRE": `{jre: {version: 17.+}}`,
}).
Execute(name, filepath.Join(fixtures, "containers", "main"))
Expect(err).NotTo(HaveOccurred(), logs.String)
// Verify SAPMachine JRE was installed from manifest
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
Expect(logs.String()).To(ContainSubstring("Installing SapMachine"))
Expect(logs.String()).To(ContainSubstring("17."))
})
})
}
}