From 3ca5d64a229a823db468fd50f708454e5fa121ff Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Thu, 5 Oct 2017 10:00:45 +0200 Subject: [PATCH] Adds integration test & edits Jenkins pipeline accordingly --- Jenkinsfile | 14 +- pom.xml | 453 +++++++++--------- .../owner/OwnerControllerITCase.java | 30 ++ 3 files changed, 275 insertions(+), 222 deletions(-) create mode 100644 src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java diff --git a/Jenkinsfile b/Jenkinsfile index 24038cb06..e5117d87f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,12 +18,20 @@ node { stage('Test') { String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; - mvn "${jacoco}:prepare-agent verify ${jacoco}:report" + mvn "${jacoco}:prepare-agent test ${jacoco}:report" // Archive JUnit results, if any - junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml' + junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml' } - + + stage('Integration Test') { + String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; + mvn "${jacoco}:prepare-agent-integration failsafe:integration-test ${jacoco}:report-integration" + + // Archive JUnit results, if any + junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml' + } + stage('SonarQube Analysis') { withCredentials([credentials]) { //noinspection GroovyAssignabilityCheck diff --git a/pom.xml b/pom.xml index a8a1eec00..776cd1a43 100644 --- a/pom.xml +++ b/pom.xml @@ -1,230 +1,245 @@ - 4.0.0 - org.springframework.samples - spring-petclinic - 1.5.2-SNAPSHOT + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.samples + spring-petclinic + 1.5.2-SNAPSHOT - - org.springframework.boot - spring-boot-starter-parent - 1.5.4.RELEASE - - petclinic - - - - - 1.8 - UTF-8 - UTF-8 - - - 3.3.6 - 1.11.4 - 2.2.4 - 1.8.0 - 3.0.6.RELEASE - - 2.7 - - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - nz.net.ultraq.thymeleaf - thymeleaf-layout-dialect - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.hsqldb - hsqldb - runtime - - - mysql - mysql-connector-java - runtime - - - - - javax.cache - cache-api - - - org.ehcache - ehcache - - - - - org.webjars - webjars-locator - - - org.webjars - jquery - ${webjars-jquery.version} - - - org.webjars - jquery-ui - ${webjars-jquery-ui.version} - - - org.webjars - bootstrap - ${webjars-bootstrap.version} - - - - - org.springframework.boot - spring-boot-devtools - runtime - - - - - spring-petclinic - - + org.springframework.boot - spring-boot-maven-plugin - - - - - build-info - - - true - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - - - - - clean - check - - - - + spring-boot-starter-parent + 1.5.4.RELEASE + + petclinic - - - pl.project13.maven - git-commit-id-plugin - - - - revision - - - - - true - yyyy-MM-dd'T'HH:mm:ssZ - true - ${project.build.outputDirectory}/git.properties - - false - - + - - ro.isdc.wro4j - wro4j-maven-plugin - ${wro4j.version} - - - generate-resources - - run - - - - - ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory - ${project.build.directory}/classes/static/resources/css - ${basedir}/src/main/wro/wro.xml - ${basedir}/src/main/wro/wro.properties - ${basedir}/src/main/less - - - + + 1.8 + UTF-8 + UTF-8 + + + 3.3.6 + 1.11.4 + 2.2.4 + 1.8.0 + 3.0.6.RELEASE + + 2.7 + + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.hsqldb + hsqldb + runtime + + + mysql + mysql-connector-java + runtime + + + + + javax.cache + cache-api + + + org.ehcache + ehcache + + + + + org.webjars + webjars-locator + + + org.webjars + jquery + ${webjars-jquery.version} + + + org.webjars + jquery-ui + ${webjars-jquery-ui.version} + + org.webjars bootstrap ${webjars-bootstrap.version} - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - html - - - - - - + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + + spring-petclinic + + + org.springframework.boot + spring-boot-maven-plugin + + + + + build-info + + + true + + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + integration-test + + integration-test + verify + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + + + + + clean + check + + + + + + + + pl.project13.maven + git-commit-id-plugin + + + + revision + + + + + true + yyyy-MM-dd'T'HH:mm:ssZ + true + ${project.build.outputDirectory}/git.properties + + false + + + + + ro.isdc.wro4j + wro4j-maven-plugin + ${wro4j.version} + + + generate-resources + + run + + + + + ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory + + ${project.build.directory}/classes/static/resources/css + ${basedir}/src/main/wro/wro.xml + ${basedir}/src/main/wro/wro.properties + ${basedir}/src/main/less + + + + org.webjars + bootstrap + ${webjars-bootstrap.version} + + + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + html + + + + + + diff --git a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java new file mode 100644 index 000000000..0fc488b1f --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java @@ -0,0 +1,30 @@ +package org.springframework.samples.petclinic.owner; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Ignore +public class OwnerControllerITCase { + + @Autowired + private TestRestTemplate restTemplate; + + /** + * Note: This test exists only for the purpose of serving as an example! Please write tests more sensible + * than this for your own applications. + */ + @Test + public void assertsUser1IsGeorgeFranklin() { + String body = this.restTemplate.getForObject("/owners/1", String.class); + assertThat(body).contains("George Franklin"); + } +}