diff --git a/Jenkinsfile b/Jenkinsfile index 24038cb06..f102d0f1f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,56 +1,81 @@ #!groovy node { - cesFqdn = "ecosystem.cloudogu.net"; - cesUrl = "https://${cesFqdn}"; - credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME'); + properties([ + // Don't run concurrent builds, because the ITs use the same port causing random failures on concurrent builds. + disableConcurrentBuilds() + ]) - stage('Checkout') { - checkout scm - } + cesFqdn = findHostName() + cesUrl = "https://${cesFqdn}" + credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME') - stage('Build') { - mvn "-DskipTests clean package" + catchError { - // archive artifact - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - } + stage('Checkout') { + checkout scm + } - stage('Test') { - String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; - mvn "${jacoco}:prepare-agent verify ${jacoco}:report" + stage('Build') { + mvn "-DskipTests clean package" - // Archive JUnit results, if any - junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml' - } - - stage('SonarQube Analysis') { - withCredentials([credentials]) { - //noinspection GroovyAssignabilityCheck - mvn "org.codehaus.mojo:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=${cesUrl}/sonar " + - "-Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD} -Dsonar.exclusions=target/**" + // archive artifact + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + + parallel( + test: { + stage('Test') { + String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606" + mvn "${jacoco}:prepare-agent test ${jacoco}:report" + } + }, + integrationTest: { + 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" + } + } + ) + + stage('SonarQube Analysis') { + withCredentials([credentials]) { + //noinspection GroovyAssignabilityCheck + mvn "org.codehaus.mojo:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=${cesUrl}/sonar " + + "-Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD} -Dsonar.exclusions=target/**" + } + } + + stage('Deploy Artifacts') { + String releaseProp = "-DaltReleaseDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/releases/"; + String snapshotProp = "-DaltSnapshotDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/snapshots/"; + mvn "-DskipTests deploy ${releaseProp} ${snapshotProp}" } } - stage('Deploy Artifacts') { - String releaseProp = "-DaltReleaseDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/releases/"; - String snapshotProp = "-DaltSnapshotDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/snapshots/"; - mvn "-DskipTests deploy ${releaseProp} ${snapshotProp}" - } - - stage('Deploy Application') { - sh "ansible-playbook playbook.yaml" - } + // Archive Unit and integration test results, if any + junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml' } -String cesFqdn; -String cesUrl; -def credentials; +// Init global vars in order to avoid NPE +String cesFqdn = '' +String cesUrl = '' +def credentials= {} void mvn(String args) { - writeSettingsXml() - sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}" - sh 'rm -f settings.xml' + writeSettingsXml() + sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}" + sh 'rm -f settings.xml' +} + +String findHostName() { + String regexMatchesHostName = 'https?://([^:/]*)' + + // Storing matcher in a variable might lead to java.io.NotSerializableException: java.util.regex.Matcher + if (!(env.JENKINS_URL =~ regexMatchesHostName)) { + script.error 'Unable to determine hostname from env.JENKINS_URL. Expecting http(s)://server:port/jenkins' + } + return (env.JENKINS_URL =~ regexMatchesHostName)[0][1] } void writeSettingsXml() { diff --git a/docs/Home.md b/docs/Home.md new file mode 100644 index 000000000..26e6186e9 --- /dev/null +++ b/docs/Home.md @@ -0,0 +1,7 @@ +# Hello world! + +Welcome to the Smeagol-Demo! Have some embedded PlantUML: + +@startuml +Bob -> Alice : hello +@enduml diff --git a/playbook.yaml b/playbook.yaml deleted file mode 100644 index ba33b91d8..000000000 --- a/playbook.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- - -- hosts: all - become: yes - gather_facts: yes - - tasks: - - name: Copy systemd descriptor - copy: - src: src/main/systemd/spring-petclinic.service - dest: /etc/systemd/system/spring-petclinic.service - notify: - - reload systemd - - - name: Copy spring-petclinic - copy: - src: target/spring-petclinic.jar - dest: /opt/spring-petclinic.jar - owner: deploy - mode: u+rwx - notify: - - restart service - - - name: Enable service - service: - name: spring-petclinic - enabled: yes - - handlers: - - name: reload systemd - systemd: - name: spring-petclinic - daemon_reload: yes - - - name: restart service - service: - name: spring-petclinic - state: restarted - 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/main/systemd/spring-petclinic.service b/src/main/systemd/spring-petclinic.service deleted file mode 100644 index d0faf84d1..000000000 --- a/src/main/systemd/spring-petclinic.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=spring-petclinic -After=syslog.target - -[Service] -User=deploy -ExecStart=/opt/spring-petclinic.jar -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target 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..3ffd69ce0 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java @@ -0,0 +1,29 @@ +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) +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"); + } +}