Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variables:
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

image: maven:3.9.6-eclipse-temurin-17

stages:
- build
- test

cache:
key: "${CI_JOB_NAME}"
paths:
- .m2/repository/
- target/

build:
stage: build
script:
- mvn clean compile

test:
stage: test
script:
- mvn verify -Pall-tests
artifacts:
when: always
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
7 changes: 7 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gitpod/workspace-full

USER gitpod

RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
sdk install java 17.0.9-tem && \
sdk default java 17.0.9-tem"
24 changes: 24 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.

image:
file: .gitpod.Dockerfile

tasks:
- init: mvn package -DskipTests=false

vscode:
extensions:
- redhat.java
- vscjava.vscode-java-debug
- vscjava.vscode-maven

# Ports to expose on workspace startup
ports:
- port: 8080
onOpen: open-preview
name: Calculator API
description: Calculator API init
visibility: private
protocol: http
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM maven:3.8.4-jdk-11
MAINTAINER ricardogarfe
FROM maven:3.9.6-eclipse-temurin-17

RUN adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password jetty
USER jetty
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,25 @@ Press Control-C to stop and remove the container.

### 3.3. Run docker-compose environment

Define a service to use repository Docker image:
Define a service to use repository Docker image and execute all tests:

```yaml
version: '3.8'
services:
calculator:
build: .
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
command: >
sh -c "mvn verify -Pall-tests"
```

Run docker-compose environment:
Run all tests in docker-compose environment:

```console
$ docker-compse up
$ docker-compose up
```

Access the web app at http://localhost:8080/api/calculator/ping in browser.
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
version: '3.8'
services:
calculator:
build: .
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
command: >
sh -c "mvn verify -Pall-tests"
131 changes: 111 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
<maven.resources.plugin.version>3.2.0</maven.resources.plugin.version>
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>2.22.2</maven.failsafe.plugin.version>
<jacoco.maven.plugin.version>0.8.7</jacoco.maven.plugin.version>
</properties>
<profiles>
Expand All @@ -40,6 +41,39 @@
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.maven.plugin.version}</version>
<configuration>
<webApp>
<contextPath>/calculator</contextPath>
</webApp>
<stopPort>8079</stopPort>
<stopKey>stop-jetty-for-it</stopKey>
<stopWait>10</stopWait>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev</id>
Expand All @@ -53,6 +87,82 @@
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.maven.plugin.version}</version>
<configuration>
<webApp>
<contextPath>/calculator</contextPath>
</webApp>
<stopPort>8079</stopPort>
<stopKey>stop-jetty-for-it</stopKey>
<stopWait>10</stopWait>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>bdd-test-environment</id>
<properties>
<!-- Used to locate the profile specific configuration file. -->
<build.profile.id>bdd-test</build.profile.id>
<!-- Only integration tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<!--
Ensures that both integration-test and verify goals of the Failsafe Maven
plugin are executed.
-->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine}</argLine>
<!--
Skips integration tests if the value of skip.integration.tests property
is true
-->
<skipTests>${skip.integration.tests}</skipTests>
<excludes>
<exclude>**/ITCalculatorAPITest.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Expand Down Expand Up @@ -188,26 +298,7 @@
<webApp>
<contextPath>/calculator</contextPath>
</webApp>
<stopPort>8079</stopPort>
<stopKey>stop-jetty-for-it</stopKey>
<stopWait>10</stopWait>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -236,7 +327,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<version>${maven.failsafe.plugin.version}</version>
<executions>
<!--
Ensures that both integration-test and verify goals of the Failsafe Maven
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
public class PingSteps {

HttpResponse response;
String host = "localhost";
int port = 8080;

@When("^I make a GET call on ([^\"]*)$")
public void iMakeAGETCallOn(String path) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(String.format("http://localhost:8080%s",path));
HttpGet httpGet = new HttpGet(String.format("http://%s:%d%s", host, port, path));
response = httpclient.execute(httpGet);
}

Expand Down