From 3e926d56becc538ac0f44945add149432fdea3f9 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 24 Mar 2019 22:37:08 +0530 Subject: [PATCH 1/2] [BAEL-10897] - Fixed spring-boot-persistence tests --- .../spring-boot-persistence/pom.xml | 6 +++++ .../com/baeldung/{ => boot}/Application.java | 2 +- .../baeldung/{ => boot}/domain/Country.java | 2 +- .../com/baeldung/{ => boot}/domain/User.java | 2 +- .../{ => boot}/naming/HibernateConfig.java | 2 +- .../naming/MetadataExtractorIntegrator.java | 2 +- .../{ => boot}/naming/entity/Account.java | 2 +- .../{ => boot}/naming/entity/Preference.java | 2 +- .../{ => boot}/repository/UserRepository.java | 5 +++-- .../baeldung/SpringBootH2IntegrationTest.java | 1 + .../SpringBootJPAIntegrationTest.java | 1 + .../SpringBootProfileIntegrationTest.java | 5 +++-- .../LegacyJpaImplNamingIntegrationTest.java | 8 +++++-- .../{ => boot}/naming/NamingConfig.java | 2 +- ...pringBootDefaultNamingIntegrationTest.java | 8 ++++--- .../StrategyLegacyHbmImplIntegrationTest.java | 9 ++++++-- .../test}/UserRepositoryIntegrationTest.java | 8 ++++--- .../config/H2TestProfileJPAConfig.java | 2 +- .../tests/UserRepositoryIntegrationTest.java | 22 ++++++++++--------- ...otTomcatConnectionPoolIntegrationTest.java | 7 ++++-- 20 files changed, 63 insertions(+), 35 deletions(-) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/Application.java (93%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/domain/Country.java (94%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/domain/User.java (96%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/naming/HibernateConfig.java (95%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/naming/MetadataExtractorIntegrator.java (97%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/naming/entity/Account.java (90%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/naming/entity/Preference.java (84%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{ => boot}/repository/UserRepository.java (97%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/{ => boot}/naming/LegacyJpaImplNamingIntegrationTest.java (90%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/{ => boot}/naming/NamingConfig.java (92%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/{ => boot}/naming/SpringBootDefaultNamingIntegrationTest.java (90%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/{ => boot}/naming/StrategyLegacyHbmImplIntegrationTest.java (88%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/{repository => boot/test}/UserRepositoryIntegrationTest.java (79%) rename persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/{ => application}/tests/UserRepositoryIntegrationTest.java (84%) diff --git a/persistence-modules/spring-boot-persistence/pom.xml b/persistence-modules/spring-boot-persistence/pom.xml index d9d3a9f9b7..72ac40222f 100644 --- a/persistence-modules/spring-boot-persistence/pom.xml +++ b/persistence-modules/spring-boot-persistence/pom.xml @@ -48,6 +48,11 @@ mysql mysql-connector-java + + javax.validation + validation-api + ${validation-api.version} + @@ -73,6 +78,7 @@ 9.0.10 1.4.197 2.23.0 + 2.0.1.Final diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/Application.java similarity index 93% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/Application.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/Application.java index 43888c2d67..cb0d0c1532 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/Application.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/Application.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/Country.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Country.java similarity index 94% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/Country.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Country.java index e6a88c7121..59227f6412 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/Country.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Country.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import static javax.persistence.GenerationType.IDENTITY; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/User.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/User.java similarity index 96% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/User.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/User.java index 9d1fc4c8ad..bdbe75cd0c 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/domain/User.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/User.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/HibernateConfig.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/HibernateConfig.java similarity index 95% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/HibernateConfig.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/HibernateConfig.java index 897e34d406..adde46e2b6 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/HibernateConfig.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/HibernateConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; import org.hibernate.jpa.boot.spi.IntegratorProvider; import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/MetadataExtractorIntegrator.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/MetadataExtractorIntegrator.java similarity index 97% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/MetadataExtractorIntegrator.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/MetadataExtractorIntegrator.java index 24b5cdea64..8702624d3f 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/MetadataExtractorIntegrator.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/MetadataExtractorIntegrator.java @@ -1,4 +1,4 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.Database; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Account.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Account.java similarity index 90% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Account.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Account.java index 6145818c5b..00e90a5ec9 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Account.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Account.java @@ -1,4 +1,4 @@ -package com.baeldung.naming.entity; +package com.baeldung.boot.naming.entity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Preference.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Preference.java similarity index 84% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Preference.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Preference.java index 928884a2c5..7711156864 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/naming/entity/Preference.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/naming/entity/Preference.java @@ -1,4 +1,4 @@ -package com.baeldung.naming.entity; +package com.baeldung.boot.naming.entity; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/repository/UserRepository.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/UserRepository.java similarity index 97% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/repository/UserRepository.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/UserRepository.java index bdc1e0af33..eae80b2e92 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/repository/UserRepository.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/UserRepository.java @@ -1,6 +1,5 @@ -package com.baeldung.repository; +package com.baeldung.boot.repository; -import com.baeldung.domain.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -11,6 +10,8 @@ import org.springframework.data.repository.query.Param; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Repository; +import com.baeldung.boot.domain.User; + import java.util.Collection; import java.util.List; import java.util.Optional; diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java index ecacf62285..01082cc6e2 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.baeldung.boot.Application; import com.baeldung.boot.config.H2JpaConfig; import com.baeldung.boot.domain.GenericEntity; import com.baeldung.boot.repository.GenericEntityRepository; diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java index 01fae2fb4d..f1ab442949 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.Application; import com.baeldung.boot.domain.GenericEntity; import com.baeldung.boot.repository.GenericEntityRepository; diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java index 65a75d7bfe..0227458987 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java @@ -10,12 +10,13 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.Application; +import com.baeldung.boot.config.H2JpaConfig; import com.baeldung.boot.domain.GenericEntity; import com.baeldung.boot.repository.GenericEntityRepository; -import com.baeldung.config.H2TestProfileJPAConfig; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { Application.class, H2TestProfileJPAConfig.class }) +@SpringBootTest(classes = { Application.class, H2JpaConfig.class }) @ActiveProfiles("test") public class SpringBootProfileIntegrationTest { @Autowired diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/LegacyJpaImplNamingIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/LegacyJpaImplNamingIntegrationTest.java similarity index 90% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/LegacyJpaImplNamingIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/LegacyJpaImplNamingIntegrationTest.java index e68be3bed8..2feee10980 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/LegacyJpaImplNamingIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/LegacyJpaImplNamingIntegrationTest.java @@ -1,6 +1,5 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; -import com.baeldung.naming.entity.Account; import org.assertj.core.api.SoftAssertions; import org.hibernate.boot.Metadata; import org.hibernate.mapping.PersistentClass; @@ -8,15 +7,20 @@ import org.hibernate.mapping.Table; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.naming.NamingConfig.Config; +import com.baeldung.boot.naming.entity.Account; + @RunWith(SpringRunner.class) @DataJpaTest @TestPropertySource(properties = { "spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl", "spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl" }) +@Import(Config.class) public class LegacyJpaImplNamingIntegrationTest extends NamingConfig { @Test diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/NamingConfig.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/NamingConfig.java similarity index 92% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/NamingConfig.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/NamingConfig.java index c3ef37aeb4..9b6574b1d7 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/NamingConfig.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/NamingConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer; import org.springframework.boot.test.context.TestConfiguration; diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/SpringBootDefaultNamingIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/SpringBootDefaultNamingIntegrationTest.java similarity index 90% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/SpringBootDefaultNamingIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/SpringBootDefaultNamingIntegrationTest.java index 089430aabb..c5c320f70c 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/SpringBootDefaultNamingIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/SpringBootDefaultNamingIntegrationTest.java @@ -1,6 +1,5 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; -import com.baeldung.naming.entity.Account; import org.assertj.core.api.SoftAssertions; import org.hibernate.boot.Metadata; import org.hibernate.mapping.PersistentClass; @@ -8,10 +7,12 @@ import org.hibernate.mapping.Table; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.boot.naming.NamingConfig.Config; +import com.baeldung.boot.naming.entity.Account; @RunWith(SpringRunner.class) @DataJpaTest @@ -19,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; "spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy", "spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy" }) +@Import(Config.class) public class SpringBootDefaultNamingIntegrationTest extends NamingConfig { @Test diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/StrategyLegacyHbmImplIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/StrategyLegacyHbmImplIntegrationTest.java similarity index 88% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/StrategyLegacyHbmImplIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/StrategyLegacyHbmImplIntegrationTest.java index 046755d9bc..ef978e5a98 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/naming/StrategyLegacyHbmImplIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/naming/StrategyLegacyHbmImplIntegrationTest.java @@ -1,6 +1,9 @@ -package com.baeldung.naming; +package com.baeldung.boot.naming; + +import com.baeldung.boot.naming.MetadataExtractorIntegrator; +import com.baeldung.boot.naming.NamingConfig.Config; +import com.baeldung.boot.naming.entity.Preference; -import com.baeldung.naming.entity.Preference; import org.assertj.core.api.SoftAssertions; import org.hibernate.boot.Metadata; import org.hibernate.mapping.PersistentClass; @@ -8,6 +11,7 @@ import org.hibernate.mapping.Table; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -19,6 +23,7 @@ import java.util.Collection; "spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl", "spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl", }) +@Import(Config.class) public class StrategyLegacyHbmImplIntegrationTest extends NamingConfig { @Test diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java similarity index 79% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java index af5abc22d7..8ec1520495 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java @@ -1,12 +1,14 @@ -package com.baeldung.repository; +package com.baeldung.boot.test; -import com.baeldung.domain.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.domain.User; +import com.baeldung.boot.repository.UserRepository; + import java.util.Collection; import static org.assertj.core.api.Assertions.assertThat; @@ -24,7 +26,7 @@ public class UserRepositoryIntegrationTest { public void givenTwoImportFilesWhenFindAllShouldReturnSixUsers() { Collection users = userRepository.findAll(); - assertThat(users.size()).isEqualTo(9); + assertThat(users.size()).isEqualTo(3); } } diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java index bcbded95fb..e0678bcf47 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java @@ -41,7 +41,7 @@ public class H2TestProfileJPAConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.domain", "com.baeldung.boot.domain" }); + em.setPackagesToScan(new String[] { "com.baeldung.boot.domain" }); em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); em.setJpaProperties(additionalProperties()); return em; diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/tests/UserRepositoryIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java similarity index 84% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/tests/UserRepositoryIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java index f27681021e..597628c5d4 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/tests/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java @@ -1,15 +1,17 @@ -package com.baeldung.springbootdatasourceconfig.tests; +package com.baeldung.springbootdatasourceconfig.application.tests; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.springbootdatasourceconfig.application.entities.User; import com.baeldung.springbootdatasourceconfig.application.repositories.UserRepository; -import java.util.List; -import java.util.Optional; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @DataJpaTest @@ -23,6 +25,6 @@ public class UserRepositoryIntegrationTest { userRepository.save(new User("Bob", "bob@domain.com")); List users = (List) userRepository.findAll(); - assertThat(users.size()).isEqualTo(1); + assertThat(users.size()).isEqualTo(3); } } diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java index eb000bbc09..76a4261a24 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java @@ -5,11 +5,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.tomcatconnectionpool.application.SpringBootConsoleApplication; + import static org.assertj.core.api.Assertions.*; import org.springframework.boot.test.context.SpringBootTest; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = {SpringBootConsoleApplication.class}) public class SpringBootTomcatConnectionPoolIntegrationTest { @Autowired @@ -17,6 +20,6 @@ public class SpringBootTomcatConnectionPoolIntegrationTest { @Test public void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() { - assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource"); + assertThat(dataSource.getClass().getName()).isEqualTo("com.zaxxer.hikari.HikariDataSource"); } } From 4195b7e40630c9f1d86439bc5a043d061e763924 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Fri, 29 Mar 2019 00:24:14 +0530 Subject: [PATCH 2/2] [BAEL-10897] - Fixed tomcat connection pool issue and CarRepositoryIntegrationTest --- persistence-modules/spring-boot-persistence/pom.xml | 6 ++++++ .../main/java/com/baeldung/{exists => boot/domain}/Car.java | 4 ++-- .../baeldung/{exists => boot/repository}/CarRepository.java | 4 +++- .../com/baeldung/exists/CarRepositoryIntegrationTest.java | 6 +++++- .../SpringBootTomcatConnectionPoolIntegrationTest.java | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{exists => boot/domain}/Car.java (93%) rename persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/{exists => boot/repository}/CarRepository.java (91%) diff --git a/persistence-modules/spring-boot-persistence/pom.xml b/persistence-modules/spring-boot-persistence/pom.xml index 72ac40222f..ca7c7306e7 100644 --- a/persistence-modules/spring-boot-persistence/pom.xml +++ b/persistence-modules/spring-boot-persistence/pom.xml @@ -25,6 +25,12 @@ org.springframework.boot spring-boot-starter-data-jpa + + + com.zaxxer + HikariCP + + org.springframework.boot diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/Car.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Car.java similarity index 93% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/Car.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Car.java index bf09caf6ff..736c12fb07 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/Car.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/domain/Car.java @@ -1,4 +1,4 @@ -package com.baeldung.exists; +package com.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -17,7 +17,7 @@ public class Car { private Integer power; private String model; - Car() { + public Car() { } diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/CarRepository.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/CarRepository.java similarity index 91% rename from persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/CarRepository.java rename to persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/CarRepository.java index a54f19f4cd..0176b14169 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/exists/CarRepository.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/repository/CarRepository.java @@ -1,10 +1,12 @@ -package com.baeldung.exists; +package com.baeldung.boot.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import com.baeldung.boot.domain.Car; + /** * @author paullatzelsperger * @since 2019-03-20 diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java index 1633df35d6..f9a48a7e66 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java @@ -13,11 +13,15 @@ import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.Car; +import com.baeldung.boot.repository.CarRepository; + import java.util.Arrays; import java.util.List; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = {Application.class}) public class CarRepositoryIntegrationTest { @Autowired diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java index 76a4261a24..5400d76fbe 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java @@ -20,6 +20,6 @@ public class SpringBootTomcatConnectionPoolIntegrationTest { @Test public void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() { - assertThat(dataSource.getClass().getName()).isEqualTo("com.zaxxer.hikari.HikariDataSource"); + assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource"); } }