Repository: iluwatar/java-design-patterns
Issue: Github reports security vulnerabilities
Labels: type: bug
info: good first issue
epic: build issue

![image](https://user-images.githubusercontent.com/582346/65894272-266ef300-e3b2-11e9-9f71-046923607de6.png)

![image](https://user-images.githubusercontent.com/582346/65894326-3dade080-e3b2-11e9-920b-b524d0edbfda.png)


Issue comments:
HI @iluwatar 
I would like to take this up
Ok @hbothra15 
is this still work in progress or shall i pick up ? @hbothra15 @iluwatar 
Ping @hbothra15 
@iluwatar Want to take this issue. Is there anything else we need to do apart from upgrading the concerned dependencies?
@gaurav9822 update the dependencies and after that verify that build and tests still work
@iluwatar I have raised a ticket on Spring JIRA.
URL - https://jira.spring.io/projects/DATAJPA/issues/DATAJPA-1610?filter=allopenissues

Also, after discussing with Spring developers, they have told to upgrade spring-boot as well in order to support spring-data 1.11.
Makes sense, those artifacts are probably dependent of each other. It's worth trying at least.

Pull request review comments:
What if the `topping` is not present? We should handle also the error case. Maybe throw the `CakeBakingException`?
`findById` returns an `Optional`, probably we don't want to log that but its contents
Returns an `Optional`..

Patch that resolved the issue:
diff --git a/layers/pom.xml b/layers/pom.xml
index 8237c8f4f6e0..a6d3d17199f6 100644
--- a/layers/pom.xml
+++ b/layers/pom.xml
@@ -41,7 +41,11 @@
 			</dependency>
 		<dependency>
 			<groupId>org.hibernate</groupId>
-			<artifactId>hibernate-entitymanager</artifactId>
+			<artifactId>hibernate-core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>javax.xml.bind</groupId>
+			<artifactId>jaxb-api</artifactId>
 		</dependency>
 		<dependency>
 	  		<groupId>commons-dbcp</groupId>
diff --git a/layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java b/layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java
index e8deee73a767..556a74c7afbf 100644
--- a/layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java
+++ b/layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java
@@ -72,18 +72,23 @@ public void bakeNewCake(CakeInfo cakeInfo) throws CakeBakingException {
       }
     }
     CakeToppingDao toppingBean = context.getBean(CakeToppingDao.class);
-    CakeTopping topping = toppingBean.findOne(matchingToppings.iterator().next().getId());
+    Optional<CakeTopping> topping = toppingBean.findById(matchingToppings.iterator().next().getId());
     CakeDao cakeBean = context.getBean(CakeDao.class);
-    Cake cake = new Cake();
-    cake.setTopping(topping);
-    cake.setLayers(foundLayers);
-    cakeBean.save(cake);
-    topping.setCake(cake);
-    toppingBean.save(topping);
-    CakeLayerDao layerBean = context.getBean(CakeLayerDao.class);
-    for (CakeLayer layer : foundLayers) {
-      layer.setCake(cake);
-      layerBean.save(layer);
+    if (topping.isPresent()) {
+      Cake cake = new Cake();
+      cake.setTopping(topping.get());
+      cake.setLayers(foundLayers);
+      cakeBean.save(cake);
+      topping.get().setCake(cake);
+      toppingBean.save(topping.get());
+      CakeLayerDao layerBean = context.getBean(CakeLayerDao.class);
+      for (CakeLayer layer : foundLayers) {
+        layer.setCake(cake);
+        layerBean.save(layer);
+      }
+    } else {
+      throw new CakeBakingException(String.format("Topping %s is not available",
+              cakeInfo.cakeToppingInfo.name));
     }
   }
 
diff --git a/layers/src/main/resources/applicationContext.xml b/layers/src/main/resources/applicationContext.xml
index eca3670b0fbf..c149094c1fa3 100644
--- a/layers/src/main/resources/applicationContext.xml
+++ b/layers/src/main/resources/applicationContext.xml
@@ -50,7 +50,7 @@
     <property name="dataSource" ref="dataSource" />
     <property name="packagesToScan" value="com.iluwatar" />
     <property name="persistenceProvider">
-      <bean class="org.hibernate.ejb.HibernatePersistence" />
+      <bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
     </property>
     <property name="jpaProperties">
       <map>
diff --git a/pom.xml b/pom.xml
index acaaef6181c5..e0f64a534aef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,10 +28,10 @@
     <inceptionYear>2014</inceptionYear>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <hibernate.version>5.0.1.Final</hibernate.version>
-        <spring.version>4.2.4.RELEASE</spring.version>
-        <spring-boot.version>1.3.3.RELEASE</spring-boot.version>
-        <spring-data.version>1.9.2.RELEASE</spring-data.version>
+        <hibernate.version>5.2.18.Final</hibernate.version>
+        <spring.version>5.0.13.RELEASE</spring.version>
+        <spring-boot.version>2.0.9.RELEASE</spring-boot.version>
+        <spring-data.version>2.0.14.RELEASE</spring-data.version>
         <h2.version>1.4.190</h2.version>
         <junit.version>4.12</junit.version>
         <junit-jupiter.version>5.0.2</junit-jupiter.version>
@@ -40,7 +40,7 @@
         <compiler.version>3.8.1</compiler.version>
         <jacoco.version>0.8.4</jacoco.version>
         <commons-dbcp.version>1.4</commons-dbcp.version>
-        <camel.version>2.16.1</camel.version>
+        <camel.version>2.24.0</camel.version>
         <guava.version>19.0</guava.version>
         <mockito.version>1.10.19</mockito.version>
         <apache-httpcomponents.version>4.5.2</apache-httpcomponents.version>
@@ -55,6 +55,7 @@
         <aws-lambda-java-events.version>2.0.1</aws-lambda-java-events.version>
         <jackson.version>2.8.5</jackson.version>
         <pmd.version>3.12.0</pmd.version>
+        <log4j.version>1.2.17</log4j.version>
         <jaxb-api.version>2.3.0</jaxb-api.version>
         <annotation-api.version>1.3.1</annotation-api.version>
     </properties>
@@ -191,11 +192,6 @@
                 <artifactId>hibernate-core</artifactId>
                 <version>${hibernate.version}</version>
             </dependency>
-            <dependency>
-                <groupId>org.hibernate</groupId>
-                <artifactId>hibernate-entitymanager</artifactId>
-                <version>${hibernate.version}</version>
-            </dependency>
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-dependencies</artifactId>
@@ -300,6 +296,11 @@
                 <artifactId>mongo-java-driver</artifactId>
                 <version>${mongo-java-driver.version}</version>
             </dependency>
+            <dependency>
+                <groupId>log4j</groupId>
+                <artifactId>log4j</artifactId>
+                <version>${log4j.version}</version>
+            </dependency>
             <dependency>
                 <groupId>javax.xml.bind</groupId>
                 <artifactId>jaxb-api</artifactId>
diff --git a/repository/pom.xml b/repository/pom.xml
index 2ccdc9da7ba5..f0340f1260ef 100644
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -44,7 +44,7 @@
         </dependency>
         <dependency>
             <groupId>org.hibernate</groupId>
-            <artifactId>hibernate-entitymanager</artifactId>
+            <artifactId>hibernate-core</artifactId>
         </dependency>
         <dependency>
             <groupId>commons-dbcp</groupId>
@@ -71,5 +71,9 @@
             <groupId>javax.annotation</groupId>
             <artifactId>javax.annotation-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/repository/src/main/java/com/iluwatar/repository/App.java b/repository/src/main/java/com/iluwatar/repository/App.java
index d96b4351ea38..c4a885380064 100644
--- a/repository/src/main/java/com/iluwatar/repository/App.java
+++ b/repository/src/main/java/com/iluwatar/repository/App.java
@@ -23,6 +23,7 @@
 package com.iluwatar.repository;
 
 import java.util.List;
+import java.util.Optional;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -84,17 +85,17 @@ public static void main(String[] args) {
     nasta.setSurname("Spotakova");
     repository.save(nasta);
 
-    LOGGER.info("Find by id 2: {}", repository.findOne(2L));
+    LOGGER.info("Find by id 2: {}", repository.findById(2L).get());
 
     // Remove record from Person
-    repository.delete(2L);
+    repository.deleteById(2L);
 
     // count records
     LOGGER.info("Count Person records: {}", repository.count());
 
     // find by name
-    Person p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
-    LOGGER.info("Find by John is {}", p);
+    Optional<Person> p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
+    LOGGER.info("Find by John is {}", p.get());
 
     // find by age
     persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
diff --git a/repository/src/main/java/com/iluwatar/repository/AppConfig.java b/repository/src/main/java/com/iluwatar/repository/AppConfig.java
index c5ccb7d00002..584c09037be7 100644
--- a/repository/src/main/java/com/iluwatar/repository/AppConfig.java
+++ b/repository/src/main/java/com/iluwatar/repository/AppConfig.java
@@ -24,6 +24,7 @@
 
 import java.sql.SQLException;
 import java.util.List;
+import java.util.Optional;
 import java.util.Properties;
 
 import javax.sql.DataSource;
@@ -32,6 +33,7 @@
 import org.hibernate.jpa.HibernatePersistenceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringBootConfiguration;
 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@@ -44,6 +46,7 @@
  *
  */
 @EnableJpaRepositories
+@SpringBootConfiguration
 public class AppConfig {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(AppConfig.class);
@@ -60,7 +63,7 @@ public DataSource dataSource() {
     basicDataSource.setUrl("jdbc:h2:~/databases/person");
     basicDataSource.setUsername("sa");
     basicDataSource.setPassword("sa");
-    return (DataSource) basicDataSource;
+    return basicDataSource;
   }
 
   /**
@@ -134,17 +137,17 @@ public static void main(String[] args) {
     nasta.setSurname("Spotakova");
     repository.save(nasta);
 
-    LOGGER.info("Find by id 2: {}", repository.findOne(2L));
+    LOGGER.info("Find by id 2: {}", repository.findById(2L).get());
 
     // Remove record from Person
-    repository.delete(2L);
+    repository.deleteById(2L);
 
     // count records
     LOGGER.info("Count Person records: {}", repository.count());
 
     // find by name
-    Person p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
-    LOGGER.info("Find by John is {}", p);
+    Optional<Person> p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
+    LOGGER.info("Find by John is {}", p.get());
 
     // find by age
     persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
diff --git a/repository/src/main/resources/applicationContext.xml b/repository/src/main/resources/applicationContext.xml
index 26d6cb3f4dc3..b27bb4c85f73 100644
--- a/repository/src/main/resources/applicationContext.xml
+++ b/repository/src/main/resources/applicationContext.xml
@@ -49,7 +49,7 @@
     <property name="dataSource" ref="dataSource" />
     <property name="packagesToScan" value="com.iluwatar" />
     <property name="persistenceProvider">
-      <bean class="org.hibernate.ejb.HibernatePersistence" />
+      <bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
     </property>
     <property name="jpaProperties">
       <map>


Test patch:
diff --git a/eip-aggregator/src/test/java/com/iluwatar/eip/aggregator/routes/AggregatorRouteTest.java b/eip-aggregator/src/test/java/com/iluwatar/eip/aggregator/routes/AggregatorRouteTest.java
index 2c7d207d6f53..2b831e01958b 100644
--- a/eip-aggregator/src/test/java/com/iluwatar/eip/aggregator/routes/AggregatorRouteTest.java
+++ b/eip-aggregator/src/test/java/com/iluwatar/eip/aggregator/routes/AggregatorRouteTest.java
@@ -28,7 +28,7 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
@@ -44,7 +44,7 @@
  * </p>
  */
 @ExtendWith(SpringExtension.class)
-@SpringApplicationConfiguration(classes = AggregatorRouteTest.class)
+@SpringBootTest(classes = AggregatorRouteTest.class)
 @ActiveProfiles("test")
 @EnableAutoConfiguration
 @ComponentScan
diff --git a/eip-splitter/src/test/java/com/iluwatar/eip/splitter/routes/SplitterRouteTest.java b/eip-splitter/src/test/java/com/iluwatar/eip/splitter/routes/SplitterRouteTest.java
index 9257a4410186..334b77da03c8 100644
--- a/eip-splitter/src/test/java/com/iluwatar/eip/splitter/routes/SplitterRouteTest.java
+++ b/eip-splitter/src/test/java/com/iluwatar/eip/splitter/routes/SplitterRouteTest.java
@@ -28,7 +28,7 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
@@ -42,7 +42,7 @@
  * </p>
  */
 @ExtendWith(SpringExtension.class)
-@SpringApplicationConfiguration(classes = SplitterRouteTest.class)
+@SpringBootTest(classes = SplitterRouteTest.class)
 @ActiveProfiles("test")
 @EnableAutoConfiguration
 @ComponentScan
diff --git a/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java
index 449f86208258..bb433f350238 100644
--- a/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java
+++ b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java
@@ -29,7 +29,7 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
@@ -45,7 +45,7 @@
  * </p>
  */
 @ExtendWith(SpringExtension.class)
-@SpringApplicationConfiguration(classes = WireTapRouteTest.class)
+@SpringBootTest(classes = WireTapRouteTest.class)
 @ActiveProfiles("test")
 @EnableAutoConfiguration
 @ComponentScan
diff --git a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java
index 4cfb6e022f51..8d7e1d94b797 100644
--- a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java
+++ b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java
@@ -28,6 +28,7 @@
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
 import javax.annotation.Resource;
 
@@ -35,9 +36,8 @@
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
-import org.springframework.test.context.support.AnnotationConfigContextLoader;
 
 import com.google.common.collect.Lists;
 
@@ -47,7 +47,7 @@
  * 
  */
 @ExtendWith(SpringExtension.class)
-@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
+@SpringBootTest(classes = { AppConfig.class })
 public class AnnotationBasedRepositoryTest {
 
   @Resource
@@ -66,7 +66,7 @@ public class AnnotationBasedRepositoryTest {
   @BeforeEach
   public void setup() {
 
-    repository.save(persons);
+    repository.saveAll(persons);
   }
 
   @Test
@@ -119,8 +119,8 @@ public void testFindAllByAgeBetweenSpec() {
   @Test
   public void testFindOneByNameEqualSpec() {
 
-    Person actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
-    assertEquals(terry, actual);
+    Optional<Person> actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
+    assertEquals(terry, actual.get());
   }
 
   @AfterEach
diff --git a/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java b/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java
index 3fb1b427b232..1839a2523e6c 100644
--- a/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java
+++ b/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java
@@ -25,9 +25,8 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
-import org.springframework.test.context.support.AnnotationConfigContextLoader;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.sql.DataSource;
@@ -42,7 +41,7 @@
  * 
  */
 @ExtendWith(SpringExtension.class)
-@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
+@SpringBootTest(classes = { AppConfig.class })
 public class AppConfigTest {
 
   @Autowired
diff --git a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java
index 5b4b8e80c055..dc976cbe72d3 100644
--- a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java
+++ b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java
@@ -28,6 +28,7 @@
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
 import javax.annotation.Resource;
 
@@ -35,7 +36,7 @@
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import com.google.common.collect.Lists;
@@ -45,7 +46,7 @@
  * by {@link org.springframework.data.jpa.domain.Specification} are also test.
  */
 @ExtendWith(SpringExtension.class)
-@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
+@SpringBootTest(properties = { "locations=classpath:applicationContext.xml" })
 public class RepositoryTest {
 
   @Resource
@@ -64,7 +65,7 @@ public class RepositoryTest {
   @BeforeEach
   public void setup() {
 
-    repository.save(persons);
+    repository.saveAll(persons);
   }
 
   @Test
@@ -115,8 +116,8 @@ public void testFindAllByAgeBetweenSpec() {
   @Test
   public void testFindOneByNameEqualSpec() {
 
-    Person actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
-    assertEquals(terry, actual);
+    Optional<Person> actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
+    assertEquals(terry, actual.get());
   }
 
   @AfterEach