MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / testJavaMain

Function testJavaMain

src/integration/java_main_test.go:13–134  ·  view source on GitHub ↗
(platform switchblade.Platform, fixtures string)

Source from the content-addressed store, hash-verified

11)
12
13func testJavaMain(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) {
14 return func(t *testing.T, context spec.G, it spec.S) {
15 var (
16 Expect = NewWithT(t).Expect
17 Eventually = NewWithT(t).Eventually
18 name string
19 )
20
21 it.Before(func() {
22 var err error
23 name, err = switchblade.RandomName()
24 Expect(err).NotTo(HaveOccurred())
25 })
26
27 it.After(func() {
28 if t.Failed() && name != "" {
29 t.Logf("❌ FAILED TEST - App/Container: %s", name)
30 t.Logf(" Platform: %s", settings.Platform)
31 }
32 if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
33 Expect(platform.Delete.Execute(name)).To(Succeed())
34 }
35 })
36
37 context("with a Java Main application", func() {
38 it("detects application with Main-Class manifest entry", func() {
39 _, logs, err := platform.Deploy.
40 WithEnv(map[string]string{
41 "BP_JAVA_VERSION": "11",
42 }).
43 Execute(name, filepath.Join(fixtures, "containers", "main"))
44 Expect(err).NotTo(HaveOccurred(), logs.String)
45
46 // Verify buildpack detects Java Main container from MANIFEST.MF
47 Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
48 Expect(logs.String()).To(ContainSubstring("Java Main"))
49 })
50 })
51
52 context("with explicit main class", func() {
53 it("detects and configures the specified main class", func() {
54 _, logs, err := platform.Deploy.
55 WithEnv(map[string]string{
56 "BP_JAVA_VERSION": "11",
57 "JBP_CONFIG_JAVA_MAIN": `{java_main_class: "io.pivotal.SimpleJava"}`,
58 }).
59 Execute(name, filepath.Join(fixtures, "containers", "main"))
60 Expect(err).NotTo(HaveOccurred(), logs.String)
61
62 // Verify buildpack detects and applies explicit main class configuration
63 Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
64 Expect(logs.String()).To(ContainSubstring("Java Main"))
65
66 // NOTE: this test does NOT verify that java_main_class actually overrides the
67 // manifest Main-Class, because:
68 // 1. The fixture's MANIFEST.MF already has Main-Class: io.pivotal.SimpleJava
69 // (same value as JBP_CONFIG_JAVA_MAIN), so the test passes even if the
70 // config is ignored.

Callers 1

TestIntegrationFunction · 0.85

Calls 2

StringMethod · 0.80
ExecuteMethod · 0.65

Tested by

no test coverage detected