Skip to content

Commit

Permalink
(feat,pom,test) make tests compatible with embedded MongoDB up to 4.0.x
Browse files Browse the repository at this point in the history
Add profiles to use embedded MongoDB on Linux and Windows, otherwise an existing MongoDB server is used (with no authentication).
Local development now use MongoDB with no authentication.
  • Loading branch information
jonathanlermitage committed Oct 22, 2018
1 parent 0cf3be4 commit a75a917
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ container:
memory: 4

test_task:
script: sh ./mvnw clean test
script: sh ./mvnw clean test -Pembed-linux,metrics
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_install:
after_success:
- bash <(curl -s https://codecov.io/bash)

script: "./mvnw clean test -Pcoverage -B"
script: "./mvnw clean test -Pembed-linux,metrics,coverage -B"

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ First, go to project's root and make the `do.sh` utility script executable: `chm

### Manually

* Install **JDK8** and **MongoDB 3.4**+. MongoDB should listen on port 27017, accept username `root` and password `woot` on the `manondev` database (authentication and data). See `src/main/resources/application-dev.yml` for details.
* Install **JDK8** and **MongoDB 4.0.x** (it should work with any version from 3.4.x to 4.1.x). MongoDB should listen on port 27017, with no authentication. See `src/main/resources/application-dev.yml` for details.
* Package and run application via `do rd`. Application will start on port 8080 with `dev` Spring profile.
* To run with another Spring profile (e.g. `prod`), package application via `do p`, go to `target/` directory and run `java -jar -Xms128m -Xmx512m -Dspring.profiles.active=prod,metrics manon.jar`.

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build_script:
- mvnw clean package -DskipTests

test_script:
- mvnw test
- mvnw test -Pembed-win,metrics

cache:
- C:\Users\appveyor\.m2
Expand Down
8 changes: 4 additions & 4 deletions do.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ if [%1] == [help] (

if [%1] == [t] (
echo mvnw clean test
mvnw clean test
mvnw clean test -Pembed-win
)
if [%1] == [tc] (
echo mvnw clean test -Pcoverage
mvnw clean test -Pcoverage
mvnw clean test -PPembed-win,coverage
)
if [%1] == [b] (
echo mvnw clean compile -DskipTests -T1
Expand Down Expand Up @@ -54,11 +54,11 @@ if [%1] == [w] (
)
if [%1] == [cv] (
echo mvnw versions:display-property-updates -U -P coverage,jib
mvnw versions:display-property-updates -U -P coverage,jib
mvnw versions:display-property-updates -U -P coverage,jib,embed-win
)
if [%1] == [uv] (
echo mvnw versions:update-properties -U -P coverage,jib
mvnw versions:update-properties -U -P coverage,jib
mvnw versions:update-properties -U -P coverage,jib,embed-win
)
if [%1] == [dt] (
echo mvnw dependency:tree
Expand Down
8 changes: 4 additions & 4 deletions do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ case "$1" in

"t")
echo "sh ./mvnw clean test"
sh ./mvnw clean test
sh ./mvnw clean test -Pembed-linux
;;

"tc")
echo "sh ./mvnw clean test -Pcoverage"
sh ./mvnw clean test -Pcoverage
sh ./mvnw clean test -Pembed-linux,coverage
;;

"b")
Expand Down Expand Up @@ -65,12 +65,12 @@ case "$1" in

"cv")
echo "sh ./mvnw versions:display-property-updates -U -P coverage,jib"
sh ./mvnw versions:display-property-updates -U -P coverage,jib
sh ./mvnw versions:display-property-updates -U -P coverage,jib,embed-linux
;;

"uv")
echo "sh ./mvnw versions:update-properties -U -P coverage,jib"
sh ./mvnw versions:update-properties -U -P coverage,jib
sh ./mvnw versions:update-properties -U -P coverage,jib,embed-linux
;;

"dt")
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
# database
mongo:
container_name: mongo
image: mongo:3.4-jessie
image: mongo:4.0.3-xenial
command: --smallfiles --logpath=/dev/null
ports:
- "27017:27017"
Expand Down
50 changes: 37 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefireArgLine>
-ea -Xms128m -Xmx256m -Dspring.profiles.active=test,metrics -Dfile.encoding=UTF-8
-Djava.awt.headless=true -XX:TieredStopAtLevel=1 -noverify
</surefireArgLine>
<surefireArgLine>-ea -Xms128m -Xmx256m -Dfile.encoding=UTF-8 -Djava.awt.headless=true -XX:TieredStopAtLevel=1 -noverify</surefireArgLine>
<profileArgLine>-Dspring.profiles.active=test,metrics</profileArgLine>

<embed.mongo.version>2.1.1</embed.mongo.version>
<janino.version>3.0.10</janino.version>
Expand All @@ -38,7 +36,6 @@
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
<versions-maven-plugin.version>2.7</versions-maven-plugin.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -172,12 +169,6 @@
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embed.mongo.version}</version>
<scope>test</scope>
</dependency>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Annotations. -->
Expand Down Expand Up @@ -245,7 +236,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<argLine>${surefireArgLine} ${profileArgLine}</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
Expand All @@ -263,6 +254,37 @@
</build>

<profiles>

<!-- Tests with embedded MongoDB: since 3.6, Linux and Windows versions need different startup params. -->
<profile>
<id>embed-linux</id>
<properties>
<profileArgLine>-Dspring.profiles.active=test-embed-linux,metrics</profileArgLine>
</properties>
<dependencies>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embed.mongo.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>embed-win</id>
<properties>
<profileArgLine>-Dspring.profiles.active=test-embed-win,metrics</profileArgLine>
</properties>
<dependencies>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embed.mongo.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

<profile>
<id>coverage</id>
<activation>
Expand Down Expand Up @@ -318,13 +340,14 @@
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!--suppress MavenModelInspection -->
<argLine>${surefireArgLine} ${coverageSurefireArgLine}</argLine>
<argLine>${surefireArgLine} ${profileArgLine} ${coverageSurefireArgLine}</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>jib</id>
<activation>
Expand Down Expand Up @@ -362,6 +385,7 @@
</plugins>
</build>
</profile>

<!--profile>
<id>java11</id>
<properties>
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
### DEV CONFIGURATION for local application ### (warning: avoid tabs, indent with two spaces)
### DEV CONFIGURATION for local application with existing MongoDB ### (warning: avoid tabs, indent with two spaces)

spring:
data:
mongodb:
host: localhost
port: 27017
database: manondev
username: root
password: woot
authentication-database: manondev
10 changes: 10 additions & 0 deletions src/test/resources/application-test-embed-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### DEV CONFIGURATION for local unit testing with embedded MongoDB on Linux x64 ### (warning: avoid tabs, indent with two spaces)

manon:
security.bcrypt.strength: 4

spring:
mongodb:
embedded:
version: 4.0.3
features: ["sync_delay", "ONLY_WITH_SSL", "NO_HTTP_INTERFACE_ARG"]
10 changes: 10 additions & 0 deletions src/test/resources/application-test-embed-win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### DEV CONFIGURATION for local unit testing with embedded MongoDB on Windows x64 ### (warning: avoid tabs, indent with two spaces)

manon:
security.bcrypt.strength: 4

spring:
mongodb:
embedded:
version: 4.0.3
features: ["sync_delay", "ONLY_WITH_SSL", "ONLY_WINDOWS_2008_SERVER", "NO_HTTP_INTERFACE_ARG"]
8 changes: 6 additions & 2 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
### DEV CONFIGURATION for local unit testing ### (warning: avoid tabs, indent with two spaces)
### DEV CONFIGURATION for local unit testing with existing MongoDB ### (warning: avoid tabs, indent with two spaces)

manon:
security.bcrypt.strength: 4

spring:
mongodb.embedded.version: 3.4.17
data:
mongodb:
host: localhost
port: 27017
database: manontest

0 comments on commit a75a917

Please sign in to comment.