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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ buildNumber.properties
# IntelliJ
.idea/
*.iml

# VSCode
.vscode
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.8.4-jdk-11

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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM maven:3.8.4-jdk-11
MAINTAINER ricardogarfe

RUN adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password jetty
USER jetty
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $ ./mvnw clean test
### 1.2 Run Integration Test

```console
$ mvn clean integration-test
$ mvn clean verify -Pintegration-test
```

### 1.3 Run Locally
Expand All @@ -83,18 +83,20 @@ To run in a different port, `mvn jetty:run -Djetty.port=<Your-Port>`.
```yaml
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Set up JDK 1.11
uses: actions/setup-java@v2.5.0
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'zulu'
cache: 'maven'
- name: Compile
run: mvn compile
- name: Test
run: mvn verify
- name: Unit Test
run: mvn test
- name: Integration API Test
run: mvn verify -Pintegration-test
```

## 3. Containerize Your Web App
Expand All @@ -120,18 +122,22 @@ 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
Expand Down
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"
133 changes: 112 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
<apache.httpcomponents.version>4.5.13</apache.httpcomponents.version>
<jetty.maven.plugin.version>11.0.7</jetty.maven.plugin.version>
<jersey.version>3.0.3</jersey.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-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
26 changes: 0 additions & 26 deletions src/main/java/com/geekshubs/calculator/Calculator.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/main/java/com/geekshubs/calculator/model/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.geekshubs.calculator.model;

public class Calculator {

int _x;
int _y;
Operation _operation;

public Calculator(int x, int y, Operation operation) {
_x = x;
_y = y;
_operation = operation;
}

public int getX() {
return _x;
}

public int getY() {
return _y;
}

public Operation getOperation() {
return _operation;
}

public int getResult() {

switch (_operation.name) {
case "add":
return _x + _y;
case "sub":
return _x - _y;
case "mul":
return _x * _y;
case "div":
return _x/_y;
default:
return 0;
}
}
}
Loading