From 7dc8fdba7eaab562793c96c3c52888669b824d04 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 16:27:21 +0100 Subject: [PATCH] JAVA-3538: Move spring-rest-testing into spring-web-modules --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-rest-testing}/.gitignore | 0 .../spring-rest-testing}/README.md | 0 .../spring-rest-testing}/pom.xml | 2 +- .../ExceptionTestingApplication.java | 48 +++---- .../controller/ExceptionController.java | 62 ++++----- .../exception/BadArgumentsException.java | 26 ++-- .../exception/InternalException.java | 26 ++-- .../exception/ResourceNotFoundException.java | 26 ++-- .../com/baeldung/persistence/IOperations.java | 0 .../com/baeldung/persistence/dao/IFooDao.java | 0 .../com/baeldung/persistence/model/Foo.java | 0 .../com/baeldung/persistence/model/User.java | 0 .../persistence/service/IFooService.java | 0 .../service/common/AbstractService.java | 0 .../persistence/service/impl/FooService.java | 0 .../java/com/baeldung/spring/Application.java | 0 .../baeldung/spring/PersistenceConfig.java | 0 .../java/com/baeldung/spring/WebConfig.java | 0 .../web/controller/FooController.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/RootController.java | 0 .../MyResourceNotFoundException.java | 0 .../web/metric/ActuatorMetricService.java | 0 .../metric/CustomActuatorMetricService.java | 0 .../web/metric/IActuatorMetricService.java | 0 .../metric/ICustomActuatorMetricService.java | 0 .../baeldung/web/metric/IMetricService.java | 0 .../com/baeldung/web/metric/MetricFilter.java | 0 .../baeldung/web/metric/MetricService.java | 0 .../baeldung/web/util/RestPreconditions.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/graph.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/Consts.java | 0 .../SpringContextIntegrationTest.java | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../ExceptionControllerUnitTest.java | 130 +++++++++--------- .../persistence/PersistenceTestSuite.java | 0 ...ractServicePersistenceIntegrationTest.java | 0 .../FooServicePersistenceIntegrationTest.java | 0 .../test/java/com/baeldung/util/IDUtil.java | 0 .../src/test/resources/.gitignore | 0 .../spring-rest-testing}/src/testFile | 0 51 files changed, 161 insertions(+), 162 deletions(-) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/README.md (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/pom.xml (99%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/IOperations.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/dao/IFooDao.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/Foo.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/IFooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/common/AbstractService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/impl/FooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/WebConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/HomeController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/RootController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricFilter.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/util/RestPreconditions.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/application.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/logback.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-h2.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-mysql.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/graph.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/Consts.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/util/IDUtil.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/resources/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/testFile (100%) diff --git a/pom.xml b/pom.xml index 208a0f5d87..d27d7350b3 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling @@ -1119,7 +1118,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 6252a6360f..640c7c3660 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -33,6 +33,7 @@ spring-rest-query-language spring-rest-shell spring-rest-simple + spring-rest-testing spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-testing/.gitignore b/spring-web-modules/spring-rest-testing/.gitignore similarity index 100% rename from spring-rest-testing/.gitignore rename to spring-web-modules/spring-rest-testing/.gitignore diff --git a/spring-rest-testing/README.md b/spring-web-modules/spring-rest-testing/README.md similarity index 100% rename from spring-rest-testing/README.md rename to spring-web-modules/spring-rest-testing/README.md diff --git a/spring-rest-testing/pom.xml b/spring-web-modules/spring-rest-testing/pom.xml similarity index 99% rename from spring-rest-testing/pom.xml rename to spring-web-modules/spring-rest-testing/pom.xml index 0e947260f4..fea8d25e4d 100644 --- a/spring-rest-testing/pom.xml +++ b/spring-web-modules/spring-rest-testing/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java index facc300dfa..b6e62b7295 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java @@ -1,25 +1,25 @@ -package com.baeldung.exceptiontesting; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * Main Application Class - uses Spring Boot. Just run this as a normal Java - * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) - * - */ -@EnableScheduling -@EnableAutoConfiguration -@ComponentScan("com.baeldung.exceptiontesting") -@SpringBootApplication -public class ExceptionTestingApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(ExceptionTestingApplication.class, args); - } - +package com.baeldung.exceptiontesting; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * Main Application Class - uses Spring Boot. Just run this as a normal Java + * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) + * + */ +@EnableScheduling +@EnableAutoConfiguration +@ComponentScan("com.baeldung.exceptiontesting") +@SpringBootApplication +public class ExceptionTestingApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(ExceptionTestingApplication.class, args); + } + } \ No newline at end of file diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java index 0f458b5f10..6d98337e40 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java @@ -1,31 +1,31 @@ -package com.baeldung.exceptiontesting.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -@RestController -public class ExceptionController { - - @GetMapping("/exception/{exception_id}") - public void getSpecificException(@PathVariable("exception_id") String pException) { - if("not_found".equals(pException)) { - throw new ResourceNotFoundException("resource not found"); - } - else if("bad_arguments".equals(pException)) { - throw new BadArgumentsException("bad arguments"); - } - else { - throw new InternalException("internal error"); - } - } - - @GetMapping("/exception/throw") - public void getException() throws Exception { - throw new Exception("error"); - } -} +package com.baeldung.exceptiontesting.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +@RestController +public class ExceptionController { + + @GetMapping("/exception/{exception_id}") + public void getSpecificException(@PathVariable("exception_id") String pException) { + if("not_found".equals(pException)) { + throw new ResourceNotFoundException("resource not found"); + } + else if("bad_arguments".equals(pException)) { + throw new BadArgumentsException("bad arguments"); + } + else { + throw new InternalException("internal error"); + } + } + + @GetMapping("/exception/throw") + public void getException() throws Exception { + throw new Exception("error"); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java index 1eb1e6a3c9..1f0e1c1ddb 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadArgumentsException extends RuntimeException { - - public BadArgumentsException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadArgumentsException extends RuntimeException { + + public BadArgumentsException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java index 8e9f0f60f3..854d6a57f0 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) -public class InternalException extends RuntimeException { - - public InternalException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) +public class InternalException extends RuntimeException { + + public InternalException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java index 469d5af96f..6d6e6ef712 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.NOT_FOUND) -public class ResourceNotFoundException extends RuntimeException { - - public ResourceNotFoundException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.NOT_FOUND) +public class ResourceNotFoundException extends RuntimeException { + + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java diff --git a/spring-rest-testing/src/main/resources/application.properties b/spring-web-modules/spring-rest-testing/src/main/resources/application.properties similarity index 100% rename from spring-rest-testing/src/main/resources/application.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/application.properties diff --git a/spring-rest-testing/src/main/resources/logback.xml b/spring-web-modules/spring-rest-testing/src/main/resources/logback.xml similarity index 100% rename from spring-rest-testing/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/logback.xml diff --git a/spring-rest-testing/src/main/resources/persistence-h2.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-h2.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties diff --git a/spring-rest-testing/src/main/resources/persistence-mysql.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-mysql.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties diff --git a/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml b/spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-testing/src/test/java/com/baeldung/Consts.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/Consts.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java similarity index 97% rename from spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java index d624efcdd0..8e1eaad977 100644 --- a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java +++ b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java @@ -1,65 +1,65 @@ -package com.baeldung.exceptiontesting.controller; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -import com.baeldung.exceptiontesting.controller.ExceptionController; -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@RunWith(SpringRunner.class) -@WebMvcTest(ExceptionController.class) -public class ExceptionControllerUnitTest{ - - @Autowired - private MockMvc mvc; - - @Test - public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { - String exceptionParam = "not_found"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) - .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); - } - - @Test - public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { - String exceptionParam = "bad_arguments"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) - .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); - } - - @Test - public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { - String exceptionParam = "dummy"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) - .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); - } - - @Test(expected = Exception.class) - public void whenGetException_thenInternalServerError() throws Exception { - mvc.perform(get("/exception/throw") - .contentType(MediaType.APPLICATION_JSON)); - } -} +package com.baeldung.exceptiontesting.controller; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.exceptiontesting.controller.ExceptionController; +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringRunner.class) +@WebMvcTest(ExceptionController.class) +public class ExceptionControllerUnitTest{ + + @Autowired + private MockMvc mvc; + + @Test + public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { + String exceptionParam = "not_found"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) + .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); + } + + @Test + public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { + String exceptionParam = "bad_arguments"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) + .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); + } + + @Test + public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { + String exceptionParam = "dummy"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) + .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); + } + + @Test(expected = Exception.class) + public void whenGetException_thenInternalServerError() throws Exception { + mvc.perform(get("/exception/throw") + .contentType(MediaType.APPLICATION_JSON)); + } +} diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java diff --git a/spring-rest-testing/src/test/resources/.gitignore b/spring-web-modules/spring-rest-testing/src/test/resources/.gitignore similarity index 100% rename from spring-rest-testing/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-testing/src/test/resources/.gitignore diff --git a/spring-rest-testing/src/testFile b/spring-web-modules/spring-rest-testing/src/testFile similarity index 100% rename from spring-rest-testing/src/testFile rename to spring-web-modules/spring-rest-testing/src/testFile