Skip to content

Commit

Permalink
Bump libs to latest versions, improve /owners POST,PUT, add tests
Browse files Browse the repository at this point in the history
- Updated pom.xml dependent libs to latest versions
- Added minimum code coverage rules in pom.xml
- Added petclinic-ermodel.png and added ref in readme.md
- /owners POST: update to ensure no id is given in request body
- /owners PUT: update to ensure bodyId (if given) matches pathId
- Add bad request tests to /owners POST,PUT
- Improve test coverage
  • Loading branch information
oldgit committed Feb 26, 2020
1 parent ab7e81b commit c01c601
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 205 deletions.
Binary file added petclinic-ermodel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
202 changes: 115 additions & 87 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-rest</artifactId>
<version>2.2.4</version>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-rest</artifactId>
<version>2.2.4</version>

<description>REST version of the Spring Petclinic sample application</description>
<description>REST version of the Spring Petclinic sample application</description>
<url>https://spring-petclinic.github.io/</url>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from Maven repository -->
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from Maven repository -->
</parent>

<properties>
<properties>
<spring-data-jdbc.version>1.2.1.RELEASE</spring-data-jdbc.version>
<springfox-swagger.version>2.6.1</springfox-swagger.version>
<jacoco.version>0.8.2</jacoco.version>
<springfox-swagger.version>2.9.2</springfox-swagger.version>
<jacoco.version>0.8.5</jacoco.version>

<docker.jib-maven-plugin.version>1.3.0</docker.jib-maven-plugin.version>
<docker.image.prefix>springcommunity</docker.image.prefix>
</properties>

<!-- repository for springfox plugin -->
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</properties>

<!-- repository for springfox plugin -->
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jdbc-core</artifactId>
<version>${spring-data-jdbc.version}</version>
Expand All @@ -88,11 +88,11 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand All @@ -113,15 +113,15 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>

<dependency>
Expand All @@ -135,13 +135,13 @@
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!-- Spring Boot Actuator displays build-related information
Expand All @@ -159,7 +159,7 @@
</configuration>
</execution>
</executions>
</plugin>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
Expand All @@ -171,6 +171,34 @@
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.87</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.74</minimum>
</limit>
</limits>
<excludes>
<!-- <exclude>com.xyz.ClassToExclude</exclude> -->
</excludes>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
Expand All @@ -195,7 +223,7 @@
</to>
</configuration>
</plugin>
</plugins>
</build>
</plugins>
</build>

</project>
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The [spring-petclinic-angular project](https://github.com/spring-petclinic/sprin

[See the presentation of the Spring Petclinic Framework version](http://fr.slideshare.net/AntoineRey/spring-framework-petclinic-sample-application)

### Petclinic ER Model

![alt petclinic-ermodel](petclinic-ermodel.png)

## Running petclinic locally

### With maven command line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,35 @@

public class BindingErrorsResponse {

private List<BindingError> bindingErrors = new ArrayList<BindingError>();

public List<BindingError> getBindingErrors() {
return bindingErrors;
}
public BindingErrorsResponse() {
this(null);
}

public BindingErrorsResponse(Integer id) {
this(null, id);
}

public BindingErrorsResponse(Integer pathId, Integer bodyId) {
boolean onlyBodyIdSpecified = pathId == null && bodyId != null;
if (onlyBodyIdSpecified) {
addBodyIdError(bodyId, "must not be specified");
}
boolean bothIdsSpecified = pathId != null && bodyId != null;
if (bothIdsSpecified && !pathId.equals(bodyId)) {
addBodyIdError(bodyId, String.format("does not match pathId: %d", pathId));
}
}

private void addBodyIdError(Integer bodyId, String message) {
BindingError error = new BindingError();
error.setObjectName("body");
error.setFieldName("id");
error.setFieldValue(bodyId.toString());
error.setErrorMessage(message);
addError(error);
}

public void setBindingErrors(List<BindingError> bindingErrors) {
this.bindingErrors = bindingErrors;
}
private List<BindingError> bindingErrors = new ArrayList<BindingError>();

public void addError(BindingError bindingError) {
this.bindingErrors.add(bindingError);
Expand Down Expand Up @@ -90,34 +110,18 @@ public BindingError() {
this.errorMessage = "";
}

protected String getObjectName() {
return objectName;
}

protected void setObjectName(String objectName) {
this.objectName = objectName;
}

protected String getFieldName() {
return fieldName;
}

protected void setFieldName(String fieldName) {
this.fieldName = fieldName;
}

protected String getFieldValue() {
return fieldValue;
}

protected void setFieldValue(String fieldValue) {
this.fieldValue = fieldValue;
}

protected String getErrorMessage() {
return errorMessage;
}

protected void setErrorMessage(String error_message) {
this.errorMessage = error_message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

public class JacksonCustomOwnerDeserializer extends StdDeserializer<Owner> {

public JacksonCustomOwnerDeserializer(){
this(null);
}
Expand All @@ -45,15 +45,13 @@ public JacksonCustomOwnerDeserializer(Class<Owner> t) {
public Owner deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
JsonNode node = parser.getCodec().readTree(parser);
Owner owner = new Owner();
int id = node.get("id").asInt();
String firstName = node.get("firstName").asText(null);
String lastName = node.get("lastName").asText(null);
String address = node.get("address").asText(null);
String city = node.get("city").asText(null);
String telephone = node.get("telephone").asText(null);

if (!(id == 0)) {
owner.setId(id);
if (node.hasNonNull("id")) {
owner.setId(node.get("id").asInt());
}
owner.setFirstName(firstName);
owner.setLastName(lastName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provid
jgen.writeStringField("name", petType.getName());
jgen.writeEndObject(); // type

jgen.writeNumberField("owner", pet.getOwner().getId());
if (pet.getOwner().getId() == null) {
jgen.writeNullField("owner");
} else {
jgen.writeNumberField("owner", pet.getOwner().getId());
}
// write visits array
jgen.writeArrayFieldStart("visits");
for (Visit visit : pet.getVisits()) {
Expand Down
Loading

0 comments on commit c01c601

Please sign in to comment.