Skip to content

Commit

Permalink
Merge pull request #22 from vpa1977/vpa1977/test-petclinic
Browse files Browse the repository at this point in the history
Provide a Spring boot webapp unit/integration test run
  • Loading branch information
vpa1977 authored Feb 16, 2023
2 parents 170b3c2 + 3a072cd commit 49689ba
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jobs:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '8'

- name: Tests Maven cache
uses: actions/cache@v3
with:
path: tests/petclinic-test/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build the chiselled-jre image
run: |
docker build \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.m2
20 changes: 20 additions & 0 deletions tests/petclinic-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG BASE_IMAGE=ubuntu/chiselled-jre:8_edge
ARG USER=app
ARG UID=101
ARG GROUP=app
ARG GID=101

FROM $BASE_IMAGE

ARG USER
ARG UID
ARG GID
USER $UID:$GID

# shell is needed for maven surefire plugin
ADD --chown=$UID:$GID sh /bin/sh
ADD --chown=$UID:$GID spring-petclinic /spring-petclinic
ADD --chown=$UID:$GID .m2 /.m2

WORKDIR /spring-petclinic

50 changes: 50 additions & 0 deletions tests/petclinic-test/runtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -ex

# This test builds tests for spring-petclinic with Maven, copies class files
# into the chiselled container and executes them in the container environemnt.
# For OpenJDK 8 we need to use tag on the last commit that used spring-boot 2.X
# as later version requires OpenJDK 17.

echo "Running Spring Petclinic self-tests"

# Replace with our development docker when it is ready
BUILD_DOCKER=eclipse-temurin:8u362-b09-jdk-jammy

# clone petclinic repository, alternative is to have a submodule here
PETCLINIC_TAG=spring-boot-2.7.3
PETCLINIC_REPO=https://github.com/vpa1977/spring-petclinic
echo cloning $PETCLINIC_TAG $PETCLINIC_REPO
git clone --branch $PETCLINIC_TAG $PETCLINIC_REPO || \
(cd spring-petclinic && \
git checkout $PETCLINIC_TAG &&
git reset --hard)

TEST_DIR=`pwd`
PROJECT_DIR=${TEST_DIR}/spring-petclinic

# Build and run tests with JDK8 container. We should replace Temurin with
# our dev container
docker run -v ${TEST_DIR}:${TEST_DIR} -w ${TEST_DIR}/spring-petclinic \
$BUILD_DOCKER \
java -classpath "${PROJECT_DIR}/.mvn/wrapper/maven-wrapper.jar" \
-Dmaven.repo.local="${TEST_DIR}/.m2" \
-Dmaven.multiModuleProjectDirectory="${PROJECT_DIR}" \
org.apache.maven.wrapper.MavenWrapperMain \
-q \
test

cp /bin/sh sh

# build docker containing maven cache and a project
docker build --build-arg BASE_IMAGE=${BASE_IMAGE:-ubuntu/chiselled-jre:8_edge} \
-t petclinic .

# now run the tests within our container
docker run --rm --tmpfs /tmp:exec petclinic \
-classpath /spring-petclinic/.mvn/wrapper/maven-wrapper.jar \
-Dmaven.repo.local=/.m2 \
-Dmaven.multiModuleProjectDirectory=/spring-petclinic \
-Dmaven.compiler.useIncrementalCompilation=false \
org.apache.maven.wrapper.MavenWrapperMain \
test

0 comments on commit 49689ba

Please sign in to comment.