From a99cc59332b88665f96b70d583dabae1fe90a43e Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sun, 1 Dec 2019 22:13:48 +0330 Subject: [PATCH] Modularizing the Module! --- .../src/main/java/com/baeldung/Application.java | 17 ----------------- .../baeldung/derivedquery/QueryApplication.java | 13 +++++++++++++ .../java/com/baeldung/like/LikeApplication.java | 13 +++++++++++++ .../java/com/baeldung/osiv/OsivApplication.java | 13 +++++++++++++ .../baeldung/{ => osiv}/model/BasicUser.java | 2 +- .../repository/BasicUserRepository.java | 4 ++-- .../{ => osiv}/service/SimpleUserService.java | 6 +++--- .../{ => osiv}/service/UserService.java | 4 ++-- .../{ => osiv}/web/DetailedUserDto.java | 4 ++-- .../baeldung/{ => osiv}/web/UserController.java | 4 ++-- .../java/com/baeldung/tx/TxApplication.java | 13 +++++++++++++ .../com/baeldung/{ => tx}/model/Payment.java | 2 +- .../UserRepositoryIntegrationTest.java | 12 ++++++------ .../like/MovieRepositoryIntegrationTest.java | 15 +++++++-------- .../osiv/UserControllerIntegrationTest.java | 7 +++---- .../tx/ManualTransactionIntegrationTest.java | 2 +- 16 files changed, 82 insertions(+), 49 deletions(-) delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java create mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java create mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/model/BasicUser.java (95%) rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/repository/BasicUserRepository.java (86%) rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/service/SimpleUserService.java (80%) rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/service/UserService.java (59%) rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/web/DetailedUserDto.java (92%) rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => osiv}/web/UserController.java (91%) create mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java rename persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/{ => tx}/model/Payment.java (96%) diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 76d8fe9f87..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootApplication -@EnableJpaRepositories -@EntityScan -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java new file mode 100644 index 0000000000..d7a1950305 --- /dev/null +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.derivedquery; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class QueryApplication { + + public static void main(String[] args) { + SpringApplication.run(QueryApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java new file mode 100644 index 0000000000..311aea3001 --- /dev/null +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.like; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class LikeApplication { + + public static void main(String[] args) { + SpringApplication.run(LikeApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java new file mode 100644 index 0000000000..4cfcf83e56 --- /dev/null +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.osiv; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OsivApplication { + + public static void main(String[] args) { + SpringApplication.run(OsivApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/BasicUser.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java similarity index 95% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/BasicUser.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java index 2dc9c18cf6..98f4e379d4 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/BasicUser.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.osiv.model; import javax.persistence.*; import java.util.Set; diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/repository/BasicUserRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java similarity index 86% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/repository/BasicUserRepository.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java index 0912759eb3..e8d5955d91 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/repository/BasicUserRepository.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.repository; +package com.baeldung.osiv.repository; import java.util.Optional; @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.model.BasicUser; +import com.baeldung.osiv.model.BasicUser; @Repository @Transactional diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/SimpleUserService.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java similarity index 80% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/SimpleUserService.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java index ab7a316129..1de51678d5 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/SimpleUserService.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java @@ -1,12 +1,12 @@ -package com.baeldung.service; +package com.baeldung.osiv.service; import java.util.Optional; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.model.BasicUser; -import com.baeldung.repository.BasicUserRepository; +import com.baeldung.osiv.model.BasicUser; +import com.baeldung.osiv.repository.BasicUserRepository; @Service public class SimpleUserService implements UserService { diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/UserService.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java similarity index 59% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/UserService.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java index 34a07199b2..3d089fa41b 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/service/UserService.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java @@ -1,6 +1,6 @@ -package com.baeldung.service; +package com.baeldung.osiv.service; -import com.baeldung.model.BasicUser; +import com.baeldung.osiv.model.BasicUser; import java.util.Optional; diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/DetailedUserDto.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java similarity index 92% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/DetailedUserDto.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java index 95a4f6eb07..fd2882c2d5 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/DetailedUserDto.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java @@ -1,6 +1,6 @@ -package com.baeldung.web; +package com.baeldung.osiv.web; -import com.baeldung.model.BasicUser; +import com.baeldung.osiv.model.BasicUser; import java.util.Set; diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/UserController.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java similarity index 91% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/UserController.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java index 867d60cc2f..5466b95166 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/web/UserController.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java @@ -1,6 +1,6 @@ -package com.baeldung.web; +package com.baeldung.osiv.web; -import com.baeldung.service.UserService; +import com.baeldung.osiv.service.UserService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java new file mode 100644 index 0000000000..4c982c91e9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.tx; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TxApplication { + + public static void main(String[] args) { + SpringApplication.run(TxApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/Payment.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java similarity index 96% rename from persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/Payment.java rename to persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java index 2c24e5777e..921a1e9275 100644 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/model/Payment.java +++ b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.tx.model; import javax.persistence.*; diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java index 22d2b7c00d..2a6e166b88 100644 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java @@ -1,11 +1,7 @@ package com.baeldung.derivedquery.repository; -import com.baeldung.Application; +import com.baeldung.derivedquery.QueryApplication; import com.baeldung.derivedquery.entity.User; -import com.baeldung.derivedquery.repository.UserRepository; -import java.time.ZonedDateTime; -import java.util.Arrays; -import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -14,10 +10,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.List; + import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) +@SpringBootTest(classes = QueryApplication.class) public class UserRepositoryIntegrationTest { private static final String USER_NAME_ADAM = "Adam"; diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java index 99d7080792..cc96b638ab 100644 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java @@ -1,10 +1,7 @@ package com.baeldung.like; -import static org.junit.Assert.assertEquals; -import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; - -import java.util.List; - +import com.baeldung.like.model.Movie; +import com.baeldung.like.repository.MovieRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -12,12 +9,14 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.like.model.Movie; -import com.baeldung.like.repository.MovieRepository; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; @RunWith(SpringRunner.class) -@SpringBootTest @Sql(scripts = { "/test-movie-data.sql" }) +@SpringBootTest(classes = LikeApplication.class) @Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD) public class MovieRepositoryIntegrationTest { @Autowired diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java index a3add5a577..350b67e1c9 100644 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java @@ -1,8 +1,7 @@ package com.baeldung.osiv; -import com.baeldung.Application; -import com.baeldung.model.BasicUser; -import com.baeldung.repository.BasicUserRepository; +import com.baeldung.osiv.model.BasicUser; +import com.baeldung.osiv.repository.BasicUserRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,8 +22,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringBootTest @AutoConfigureMockMvc -@ContextConfiguration(classes = Application.class) @ActiveProfiles("test") +@ContextConfiguration(classes = OsivApplication.class) class UserControllerIntegrationTest { @Autowired diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java index 954ff3baf6..01551348c9 100644 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java @@ -1,6 +1,6 @@ package com.baeldung.tx; -import com.baeldung.model.Payment; +import com.baeldung.tx.model.Payment; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test;