Skip to content

Commit

Permalink
Added examples tests for Chapter 9 - testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed Feb 2, 2018
1 parent b7d799a commit 96b3447
Show file tree
Hide file tree
Showing 148 changed files with 5,382 additions and 292 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ jobs:
- checkout
- restore_cache:
key: ftgo-application-{{ checksum "build.gradle" }}
- run: TERM=dumb ./build-contract.sh
- run: TERM=dumb ./gradlew testClasses
- save_cache:
paths:
- ~/.gradle
- ~/.m2
key: ftgo-application-{{ checksum "build.gradle" }}
- run:
command: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ build/
*.idea/
*.iml
*.log
out
target
.serverless
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ All the services' business logic is implemented using Domain-Driven design aggre

=== Building

Temporary: Build the Spring Cloud Contracts using this command:

```
./build-contracts.sh
```

Build the services using this command:

```
Expand Down
6 changes: 5 additions & 1 deletion build-and-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ echo data is prepared

docker-compose up -d --build eventuate-local-cdc-service tram-cdc-service

./gradlew -x :ftgo-end-to-end-tests:test build
# TODO Temporarily

./build-contracts.sh

./gradlew -x :ftgo-end-to-end-tests:test $* build

docker-compose up -d --build

Expand Down
7 changes: 7 additions & 0 deletions build-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash -e

CONTRACT_DIRS="common-contracts ftgo-order-service-contracts ftgo-restaurant-order-service-contracts"

for dir in $CONTRACT_DIRS ; do
(cd $dir ; ./mvnw install)
done
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ subprojects {

apply plugin: "java"

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/eventuateio-oss/eventuate-maven-release"
}
eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }

// For the contracts
mavenLocal()
}

}
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.enabled=false
34 changes: 34 additions & 0 deletions buildSrc/src/main/groovy/ComponentTestsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test

class ComponentTestsPlugin implements Plugin<Project> {

@Override
void apply(Project project) {
project.sourceSets {
componentTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir project.file('src/component-test/java')
}
resources.srcDir project.file('src/component-test/resources')
}
}

project.configurations {
componentTestCompile.extendsFrom testCompile
componentTestRuntime.extendsFrom testRuntime
}

project.task("componentTest", type: Test) {
testClassesDir = project.sourceSets.componentTest.output.classesDir
classpath = project.sourceSets.componentTest.runtimeClasspath
}

project.tasks.withType(Test) {
reports.html.destination = project.file("${project.reporting.baseDir}/${name}")
}
}
}
34 changes: 34 additions & 0 deletions buildSrc/src/main/groovy/IntegrationTestsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test

class IntegrationTestsPlugin implements Plugin<Project> {

@Override
void apply(Project project) {
project.sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir project.file('src/integration-test/java')
}
resources.srcDir project.file('src/integration-test/resources')
}
}

project.configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

project.task("integrationTest", type: Test) {
testClassesDir = project.sourceSets.integrationTest.output.classesDir
classpath = project.sourceSets.integrationTest.runtimeClasspath
}

project.tasks.withType(Test) {
reports.html.destination = project.file("${project.reporting.baseDir}/${name}")
}
}
}
Binary file added common-contracts/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions common-contracts/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 changes: 2 additions & 0 deletions common-contracts/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

1 change: 1 addition & 0 deletions common-contracts/TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory needs to be per-service
50 changes: 50 additions & 0 deletions common-contracts/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE"
// if using Stub Runner (consumer side) only remove this dependency
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:1.1.1.RELEASE"
}
}

repositories {
mavenCentral()
}

group = "net.chrisrichardson.ftgo.contracts"
version = "1.0-SNAPSHOT"
apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
apply plugin: 'spring-cloud-contract'
apply plugin: 'maven'

uploadArchives {
repositories {
mavenDeployer {
repository(url: deployUrl)
pom.withXml {
asNode().appendNode('classifier', 'stubs')
}
}
}
}

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-contract-dependencies:1.1.4.RELEASE'
}
}

dependencies {
// testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
}

/*
// In this section you define all Spring Cloud Contract Verifier Gradle Plugin properties
contracts {
baseClassForTests = 'com.example.MvcTest'
// fully qualified name to a class that will be the base class for your generated test classes
}
*/
9 changes: 9 additions & 0 deletions common-contracts/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

org.gradle.jvmargs=-XX:MaxPermSize=512m

deployUrl=file:///Users/cer/.m2/repository

springBootVersion=1.5.4.RELEASE

eventuateClientVersion=0.14.0.RELEASE
eventuateLocalVersion=0.9.0.RELEASE
Binary file not shown.
6 changes: 6 additions & 0 deletions common-contracts/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Sat Jan 03 09:40:05 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-3.5-bin.zip
164 changes: 164 additions & 0 deletions common-contracts/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
Loading

0 comments on commit 96b3447

Please sign in to comment.