This commit is contained in:
raynfall 2018-01-13 22:29:16 +00:00 committed by GitHub
commit 438dfa15af
12 changed files with 298 additions and 45 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ target/*
*.iml
/target
_site/
.vagrant/

View file

@ -1,2 +1,2 @@
language: java
jdk: oraclejdk8
language: java
jdk: oraclejdk8

37
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,37 @@
pipeline {
tools {
maven 'Maven 3.5.0'
}
agent any
stages {
stage('Build, Test, and Package') {
steps {
sh "mvn clean package"
}
}
stage('SonarQube Analysis') {
steps {
startSonarQubeAnalysis "SonarQube_Scanner_3.0.3.778", "Staging", "${env.WORKSPACE}", "sonar-project.properties"
}
}
stage('SonarQube Quality Gate') {
// we don't want to tie up an agent for this
agent none
steps {
waitForSonarQubeAnalysis 60, ['OK','WARN']
}
}
stage('Approve for QA') {
steps {
// input 'Sally forth?'
echo 'Pipeline done'
}
}
}
}

75
Vagrantfile vendored Normal file
View file

@ -0,0 +1,75 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "centos/7"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 8080, host: 8484
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.provision :file, source: "target/spring-petclinic-1.4.2.jar", destination: "/tmp/spring-petclinic-1.4.2.jar", run: "always"
config.vm.provision :shell, inline: "java -jar /tmp/spring-petclinic-1.4.2.jar &", run: "always"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end

22
bootstrap.sh Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# update all existing packages
sudo yum -y update
# install wget and dos2unix
sudo yum -y install wget
sudo yum -y install dos2unix
# download java
sudo wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm" \
-O /tmp/jdk-8-linux-x64.rpm
# install java
sudo yum -y install /tmp/jdk-8-linux-x64.rpm
sudo rm /tmp/jdk-8-linux-x64.rpm
# run the application
#java -jar /tmp/spring-petclinic-1.4.2.jar &

28
buildspec.yml Normal file
View file

@ -0,0 +1,28 @@
version: 0.2
#env:
# variables:
# key: "value"
# key: "value"
phases:
# install:
# commands:
# - command
# - command
# pre_build:
# commands:
# - command
# - command
build:
commands:
- mvn clean package
# post_build:
# commands:
# - command
# - command
artifacts:
files:
- target/spring-petclinic-1.4.2.jar
discard-paths: yes
# base-directory: location

90
pom.xml
View file

@ -12,10 +12,8 @@
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<name>petclinic</name>
<properties>
<!-- Generic properties -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -30,7 +28,33 @@
<cobertura.version>2.7</cobertura.version>
</properties>
<!--
<repositories>
<repository>
<id>nexus</id>
<url>http://localhost:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>nexus-local</id>
<url>http://localhost:8081/repository/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>nexus-local</id>
<url>http://localhost:8081/repository/maven-releases</url>
</repository>
</distributionManagement>
-->
<scm>
<connection>scm:git:https://github.com/Blackhound/spring-petclinic</connection>
<developerConnection>scm:git:https://github.com/Blackhound/spring-petclinic</developerConnection>
<url>https://localhost:8080</url>
</scm>
<dependencies>
<!-- Spring and Spring Boot dependencies -->
<dependency>
@ -108,10 +132,30 @@
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4-rc-3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.5</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
@ -133,25 +177,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<check />
<runOrder>random</runOrder>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
<!-- Spring Boot Actuator displays build-related information if a git.properties
file is present at the classpath -->
<!--
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
@ -171,6 +208,7 @@
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
-->
<plugin>
<groupId>ro.isdc.wro4j</groupId>
@ -199,24 +237,15 @@
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- integrate maven-cobertura-plugin to project site -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<formats>
<format>html</format>
</formats>
<check />
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</reporting>
<!-- Apache 2 license -->
<licenses>
@ -225,5 +254,4 @@
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
</project>

View file

@ -15,6 +15,7 @@ You can then access petclinic here: http://localhost:8080/
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
## In case you find a bug/suggested improvement for Spring Petclinic
## Minor change - Ray
Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
@ -104,8 +105,6 @@ The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues)
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <http://editorconfig.org>. If you have not previously done so, please fill out and submit the https://cla.pivotal.io/sign/spring[Contributor License Agreement].
# License
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0).
[spring-petclinic]: https://github.com/spring-projects/spring-petclinic

18
sonar-project.properties Executable file → Normal file
View file

@ -1,13 +1,19 @@
# Required metadata
sonar.projectKey=java-sonar-runner-simple
sonar.projectName=Simple Java project analyzed with the SonarQube Runner
sonar.projectVersion=1.0
sonar.projectKey=org.springframework.samples:spring-petclinic
sonar.projectName=Spring Pet Clinic
sonar.projectVersion=1.4.2
# Comma-separated paths to directories with sources (required)
sonar.sources=src
#sonar.sources=src/main/java,src/main/less,src/main/resources,src/main/wro
sonar.sources=src/main
# Language
sonar.language=java
#sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
sonar.sourceEncoding=UTF-8
# other stuff
sonar.host.url=http://mssonarstg81.morningstar.com:9000
sonar.java.binaries=target/classes
sonar.junit.reportsPath=target/surefire-reports

View file

@ -6,6 +6,7 @@ import javax.cache.configuration.MutableConfiguration;
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
/**
@ -16,6 +17,7 @@ import org.springframework.context.annotation.Profile;
@Profile("production")
class CacheConfig {
@Bean
public JCacheManagerCustomizer cacheManagerCustomizer() {
return cm -> {

View file

@ -17,7 +17,8 @@ package org.springframework.samples.petclinic.vet;
import java.util.Collection;
import org.springframework.cache.annotation.Cacheable;
import javax.cache.annotation.CacheResult;
import org.springframework.dao.DataAccessException;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;
@ -39,8 +40,7 @@ public interface VetRepository extends Repository<Vet, Integer> {
* @return a <code>Collection</code> of <code>Vet</code>s
*/
@Transactional(readOnly = true)
@Cacheable("vets")
@CacheResult(cacheName = "vets")
Collection<Vet> findAll() throws DataAccessException;
}
}

View file

@ -0,0 +1,55 @@
package org.springframework.samples.petclinic.model;
//import static org.assertj.core.api.Assertions.assertThat;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import spock.lang.Specification;
/**
* @author Chris Jones
* Simple tests adapted to use the Spock acceptance test framework.
*/
public class ValidatorSpockTests extends Specification {
private Validator createValidator() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.afterPropertiesSet();
return localValidatorFactoryBean;
}
// 1. validate against blank first name
def "first name cannot be empty"() {
setup:
def person = new Person();
def validator = createValidator();
when:
person.setFirstName("")
person.setLastName("smith")
Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);
then:
constraintViolations.size() == 1;
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
violation.getPropertyPath().toString().equals("firstName");
violation.getMessage().equals("may not be empty");
}
// 2. TODO: validate against null first name.
// 3. TODO: validate a against a valid first name (non-empty, non-null value).
// 4. TODO: validate against empty last name
// 5. TODO: validate against null last name
// 6. TODO: validate a against a valid last name (non-empty, non-null value).
}