mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:05:49 +00:00
Added a new Spock test file. Updated the POM file to suport Spock.
This commit is contained in:
parent
f09c20793c
commit
12ecbc5c0f
2 changed files with 82 additions and 0 deletions
27
pom.xml
27
pom.xml
|
@ -135,6 +135,20 @@
|
|||
<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>
|
||||
|
@ -235,6 +249,19 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
|
|
|
@ -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).
|
||||
}
|
Loading…
Reference in a new issue