Skip to content

Commit

Permalink
Add simple WAR test that does not use Spring
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Aug 26, 2024
1 parent caa38b6 commit 62320c9
Show file tree
Hide file tree
Showing 25 changed files with 589 additions and 30 deletions.
31 changes: 31 additions & 0 deletions java/war-spring/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
119 changes: 119 additions & 0 deletions java/war-spring/smoke_test/war_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package war_test

import (
"flag"
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/paketo-buildpacks/samples/tests"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

var builders tests.BuilderFlags

func init() {
flag.Var(&builders, "name", "the name a builder to test with")
}
func TestWARSpring(t *testing.T) {
Expect := NewWithT(t).Expect

Expect(len(builders)).NotTo(Equal(0))

SetDefaultEventuallyTimeout(60 * time.Second)

suite := spec.New("Java - WAR Spring", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("WAR Spring with %s builder", builder), testWARWithBuilder(builder), spec.Sequential())
}
suite.Run(t)
}

func testWARWithBuilder(builder 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

pack occam.Pack
docker occam.Docker
)

it.Before(func() {
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})

context("detects a Java app", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
err := docker.Container.Remove.Execute(container.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker container: exit status 1: Container name cannot be empty"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(os.RemoveAll(source)).To(Succeed())
})

context("app uses war", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
WithEnv(map[string]string{"BP_TOMCAT_VERSION": "10.1"}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for CA Certificates")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for BellSoft Liberica")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Maven")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Apache Tomcat")))

container, err = docker.Container.Run.
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("UP")).OnPort(8080).WithEndpoint("/actuator/health"))
})
})
})
}
}
9 changes: 9 additions & 0 deletions java/war/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

34 changes: 4 additions & 30 deletions java/war/.gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
# Ignore Gradle project-specific cache directory
.gradle

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
# Ignore Gradle build output directory
build
26 changes: 26 additions & 0 deletions java/war/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id 'war'
}

group = 'io.paketo'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_17
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
providedCompile 'jakarta.platform:jakarta.jakartaee-api:10.0.0'
providedCompile 'org.eclipse.microprofile:microprofile:6.1'

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.3'
}

test {
useJUnitPlatform()
}
2 changes: 2 additions & 0 deletions java/war/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.parallel=true
org.gradle.caching=true
Binary file added java/war/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions java/war/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 62320c9

Please sign in to comment.