diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WebAppInitializer.java b/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WebAppInitializer.java deleted file mode 100644 index 9813077aab..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WebAppInitializer.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.controller; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -import com.baeldung.config.WebAppConfiguration_BeanNameUrlHandlerMapping; - -public class WebAppInitializer implements WebApplicationInitializer { - - public void onStartup(ServletContext container) throws ServletException { - - AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); - ctx.register(WebAppConfiguration_BeanNameUrlHandlerMapping.class); - ctx.setServletContext(container); - - ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); - - servlet.setLoadOnStartup(1); - servlet.addMapping("/"); - - } -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WelcomeController.java b/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WelcomeController.java deleted file mode 100644 index baf9dd9ece..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/WelcomeController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -public class WelcomeController extends AbstractController { - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - System.out.println("Inside Welcome Controller"); - - ModelAndView model = new ModelAndView("welcome"); - - return model; - } -} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ControllerClassNameHandlerMapping.java b/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ControllerClassNameHandlerMapping.java deleted file mode 100644 index ac822dbe5a..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ControllerClassNameHandlerMapping.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -import com.baeldung.controller.WelcomeController; - -@Configuration -public class WebAppConfiguration_ControllerClassNameHandlerMapping { - - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Bean - public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() { - ControllerClassNameHandlerMapping controllerClassNameHandlerMapping = new ControllerClassNameHandlerMapping(); - return controllerClassNameHandlerMapping; - } - - @Bean - public WelcomeController welcome() { - WelcomeController welcome = new WelcomeController(); - return welcome; - } - -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_SimpleUrlHandlerMapping.java b/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_SimpleUrlHandlerMapping.java deleted file mode 100644 index 3b8534500d..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_SimpleUrlHandlerMapping.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.config; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -import com.baeldung.controller.WelcomeController; - - -@Configuration -public class WebAppConfiguration_SimpleUrlHandlerMapping { - - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Bean - public SimpleUrlHandlerMapping simpleUrlHandlerMapping() { - SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping(); - Map urlMap = new HashMap<>(); - urlMap.put("/simpleUrlWelcome", welcome()); - simpleUrlHandlerMapping.setUrlMap(urlMap); - return simpleUrlHandlerMapping; - } - - @Bean - public WelcomeController welcome() { - WelcomeController welcome = new WelcomeController(); - return welcome; - } - -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameHandlerMappingConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameHandlerMappingConfig.java deleted file mode 100644 index fce1d50a00..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameHandlerMappingConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.spring.web.config; - -import com.baeldung.web.controller.handlermapping.ExampleTwoController; -import com.baeldung.web.controller.handlermapping.WelcomeController; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; -import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -@Configuration -public class BeanNameHandlerMappingConfig { - - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Bean - public BeanNameUrlHandlerMapping controllerClassNameHandlerMapping() { - BeanNameUrlHandlerMapping beanNameUrlHandlerMapping = new BeanNameUrlHandlerMapping(); - return beanNameUrlHandlerMapping; - } - - @Bean(name="/welcomeBean") - public WelcomeController welcomeBean() { - WelcomeController welcome = new WelcomeController(); - return welcome; - } - - @Bean(name="/ex") - public ExampleTwoController exampleTwo() { - ExampleTwoController exampleTwo = new ExampleTwoController(); - return exampleTwo; - } - -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_BeanNameUrlHandlerMapping.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameUrlHandlerMappingConfig.java similarity index 69% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_BeanNameUrlHandlerMapping.java rename to spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameUrlHandlerMappingConfig.java index 5ed738a8c4..fe220fee44 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_BeanNameUrlHandlerMapping.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/BeanNameUrlHandlerMappingConfig.java @@ -1,15 +1,14 @@ -package com.baeldung.config; +package com.baeldung.spring.web.config; +import com.baeldung.web.controller.handlermapping.WelcomeController; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; import org.springframework.web.servlet.view.InternalResourceViewResolver; -import com.baeldung.controller.WelcomeController; - @Configuration -public class WebAppConfiguration_BeanNameUrlHandlerMapping { +public class BeanNameUrlHandlerMappingConfig { @Bean public ViewResolver viewResolver() { @@ -21,14 +20,12 @@ public class WebAppConfiguration_BeanNameUrlHandlerMapping { @Bean BeanNameUrlHandlerMapping beanNameUrlHandlerMapping() { - BeanNameUrlHandlerMapping bean = new BeanNameUrlHandlerMapping(); - return bean; + return new BeanNameUrlHandlerMapping(); } @Bean("/beanNameUrl") public WelcomeController welcome() { - WelcomeController welcome = new WelcomeController(); - return welcome; + return new WelcomeController(); } } diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ControllerClassNameHandlerMappingConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ControllerClassNameHandlerMappingConfig.java index b03b781e5a..0f67624658 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ControllerClassNameHandlerMappingConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ControllerClassNameHandlerMappingConfig.java @@ -1,42 +1,35 @@ package com.baeldung.spring.web.config; -import com.baeldung.web.controller.handlermapping.ExampleTwoController; import com.baeldung.web.controller.handlermapping.WelcomeController; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping; import org.springframework.web.servlet.view.InternalResourceViewResolver; +@EnableWebMvc @Configuration public class ControllerClassNameHandlerMappingConfig { - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } + @Bean + public ViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } - @Bean - public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() { - ControllerClassNameHandlerMapping controllerClassNameHandlerMapping = new ControllerClassNameHandlerMapping(); - return controllerClassNameHandlerMapping; - } + @Bean + public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() { + ControllerClassNameHandlerMapping controllerClassNameHandlerMapping = new ControllerClassNameHandlerMapping(); + return controllerClassNameHandlerMapping; + } - @Bean - public WelcomeController welcome() { - WelcomeController welcome = new WelcomeController(); - return welcome; - } + @Bean + public WelcomeController welcome() { + return new WelcomeController(); + } - @Bean - public ExampleTwoController exampleTwo() { - ExampleTwoController exampleTwo = new ExampleTwoController(); - return exampleTwo; - } } diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ConfiguringPriorities.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/HandlerMappingPrioritiesConfig.java similarity index 85% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ConfiguringPriorities.java rename to spring-mvc-java/src/main/java/com/baeldung/spring/web/config/HandlerMappingPrioritiesConfig.java index ba3607faf3..249c816823 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/JavaConfig/WebAppConfiguration_ConfiguringPriorities.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/HandlerMappingPrioritiesConfig.java @@ -1,20 +1,20 @@ -package com.baeldung.config; +package com.baeldung.spring.web.config; import java.util.HashMap; import java.util.Map; +import com.baeldung.web.controller.handlermapping.BaeldungController; +import com.baeldung.web.controller.handlermapping.TestController; +import com.baeldung.web.controller.handlermapping.WelcomeController; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping; -import com.baeldung.controller.BaeldungController; -import com.baeldung.controller.WelcomeController; -import com.baeldung.controller.TestController; @Configuration -public class WebAppConfiguration_ConfiguringPriorities { +public class HandlerMappingPrioritiesConfig { @Bean BeanNameUrlHandlerMapping beanNameUrlHandlerMapping() { diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/SimpleUrlHandlerMappingConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/SimpleUrlHandlerMappingConfig.java index aef7750dc0..a81b2fa14e 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/SimpleUrlHandlerMappingConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/SimpleUrlHandlerMappingConfig.java @@ -1,6 +1,8 @@ package com.baeldung.spring.web.config; -import com.baeldung.web.controller.handlermapping.ExampleTwoController; +import java.util.HashMap; +import java.util.Map; + import com.baeldung.web.controller.handlermapping.WelcomeController; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -8,40 +10,34 @@ import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.view.InternalResourceViewResolver; -import java.util.HashMap; -import java.util.Map; + + + @Configuration public class SimpleUrlHandlerMappingConfig { - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } + @Bean + public ViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } - @Bean - public SimpleUrlHandlerMapping simpleUrlHandlerMapping() { - SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping(); - Map urlMap = new HashMap<>(); - urlMap.put("/simpleUrlWelcome", welcome()); - urlMap.put("/exampleTwo", exampleTwo()); - simpleUrlHandlerMapping.setUrlMap(urlMap); - return simpleUrlHandlerMapping; - } + @Bean + public SimpleUrlHandlerMapping simpleUrlHandlerMapping() { + SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping(); + Map urlMap = new HashMap<>(); + urlMap.put("/simpleUrlWelcome", welcome()); + simpleUrlHandlerMapping.setUrlMap(urlMap); + return simpleUrlHandlerMapping; + } - @Bean - public WelcomeController welcome() { - WelcomeController welcome = new WelcomeController(); - return welcome; - } + @Bean + public WelcomeController welcome() { + return new WelcomeController(); + } - @Bean - public ExampleTwoController exampleTwo() { - ExampleTwoController exampleTwo = new ExampleTwoController(); - return exampleTwo; - } } diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/BaeldungController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/BaeldungController.java similarity index 83% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/BaeldungController.java rename to spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/BaeldungController.java index 9cc55d3554..363fa74b66 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/BaeldungController.java +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/BaeldungController.java @@ -1,18 +1,15 @@ -package com.baeldung.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +package com.baeldung.web.controller.handlermapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + public class BaeldungController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - System.out.println("Inside Welcome Baeldung Controller"); - ModelAndView model = new ModelAndView("baeldung"); - return model; } diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/ExampleTwoController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/ExampleTwoController.java deleted file mode 100644 index efdec6408c..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/ExampleTwoController.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.web.controller.handlermapping; - -import org.springframework.stereotype.Controller; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -@Controller -public class ExampleTwoController extends AbstractController -{ - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, - HttpServletResponse response) throws Exception { - System.out.println("Inside ExampleTwo Controller"); - - ModelAndView model = new ModelAndView("exampleTwo"); - - return model; - } -} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/TestController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/TestController.java similarity index 74% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/TestController.java rename to spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/TestController.java index f0d69de8b0..0f94321168 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/Controller/TestController.java +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/TestController.java @@ -1,18 +1,15 @@ -package com.baeldung.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +package com.baeldung.web.controller.handlermapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + public class TestController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - System.out.println("Inside Welcome two Controller"); - - ModelAndView model = new ModelAndView("test"); - + ModelAndView model = new ModelAndView("test"); return model; } diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java index 396244f01c..1598583127 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java @@ -8,15 +8,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller -public class WelcomeController extends AbstractController -{ - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, - HttpServletResponse response) throws Exception { - System.out.println("Inside BeanNameMappingExampleOne Controller"); +public class WelcomeController extends AbstractController { - ModelAndView model = new ModelAndView("test"); - - return model; + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + return new ModelAndView("welcome"); } } \ No newline at end of file diff --git a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/BeanNameMappingConfigTest.java b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/BeanNameMappingConfigTest.java index 9cc992bb3c..f2e78c3309 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/BeanNameMappingConfigTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/BeanNameMappingConfigTest.java @@ -1,10 +1,6 @@ -package come.baeldung.test; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; +package com.baeldung.handlermapping; +import com.baeldung.spring.web.config.BeanNameUrlHandlerMappingConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,12 +13,15 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.config.WebAppConfiguration_BeanNameUrlHandlerMapping; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration(classes = WebAppConfiguration_BeanNameUrlHandlerMapping.class) +@ContextConfiguration(classes = BeanNameUrlHandlerMappingConfig.class) public class BeanNameMappingConfigTest { @Autowired diff --git a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/ControllerClassNameHandlerMappingTest.java b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/ControllerClassNameHandlerMappingTest.java index 24fd865c11..79dd8513a1 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/ControllerClassNameHandlerMappingTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/ControllerClassNameHandlerMappingTest.java @@ -1,4 +1,4 @@ -package come.baeldung.test; +package com.baeldung.handlermapping; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -17,11 +17,11 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.config.WebAppConfiguration_ControllerClassNameHandlerMapping; +import com.baeldung.spring.web.config.ControllerClassNameHandlerMappingConfig; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration(classes = WebAppConfiguration_ControllerClassNameHandlerMapping.class) +@ContextConfiguration(classes = ControllerClassNameHandlerMappingConfig.class) public class ControllerClassNameHandlerMappingTest { @Autowired @@ -36,6 +36,6 @@ public class ControllerClassNameHandlerMappingTest { @Test public void whenControllerClassNameMapping_thenMappedOK() throws Exception { - mockMvc.perform(get("/welcometest")).andExpect(status().isOk()).andExpect(view().name("welcome")).andDo(print()); + mockMvc.perform(get("/welcome")).andExpect(status().isOk()).andExpect(view().name("welcome")).andDo(print()); } } \ No newline at end of file diff --git a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/HandlerMappingPriorityConfigTest.java b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/HandlerMappingPriorityConfigTest.java index cfb51fd5cc..aa48f02c09 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/HandlerMappingPriorityConfigTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/HandlerMappingPriorityConfigTest.java @@ -1,4 +1,4 @@ -package come.baeldung.test; +package com.baeldung.handlermapping; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -17,11 +17,11 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.config.WebAppConfiguration_ConfiguringPriorities; +import com.baeldung.spring.web.config.HandlerMappingPrioritiesConfig; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration(classes = WebAppConfiguration_ConfiguringPriorities.class) +@ContextConfiguration(classes = HandlerMappingPrioritiesConfig.class) public class HandlerMappingPriorityConfigTest { @Autowired diff --git a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/SimpleUrlMappingConfigTest.java b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/SimpleUrlMappingConfigTest.java index 8c9405abfc..847b00323b 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/SimpleUrlMappingConfigTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/HandlerMapping/SimpleUrlMappingConfigTest.java @@ -1,10 +1,6 @@ -package come.baeldung.test; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; +package com.baeldung.handlermapping; +import com.baeldung.spring.web.config.SimpleUrlHandlerMappingConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,11 +13,14 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.config.WebAppConfiguration_SimpleUrlHandlerMapping; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration(classes = WebAppConfiguration_SimpleUrlHandlerMapping.class) +@ContextConfiguration(classes = SimpleUrlHandlerMappingConfig.class) public class SimpleUrlMappingConfigTest { @Autowired diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/BeanNameMappingConfigTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/BeanNameMappingConfigTest.java deleted file mode 100644 index dc6d861db2..0000000000 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/BeanNameMappingConfigTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.web.controller; - -import com.baeldung.spring.web.config.BeanNameHandlerMappingConfig; -import com.baeldung.spring.web.config.SimpleUrlHandlerMappingConfig; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = BeanNameHandlerMappingConfig.class) -public class BeanNameMappingConfigTest { - - @Autowired - private WebApplicationContext webAppContext; - private MockMvc mockMvc; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build(); - } - - @Test - public void whenBeanNameMapping_thenMappedOK() throws Exception { - mockMvc.perform(get("/welcomeBean")).andExpect(status().isOk()).andExpect(view().name("test")).andDo(print()); - } -} diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/ControllerClassNameHandlerMappingTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/ControllerClassNameHandlerMappingTest.java deleted file mode 100644 index ea6243a1eb..0000000000 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/ControllerClassNameHandlerMappingTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.web.controller; - -import com.baeldung.spring.web.config.ControllerClassNameHandlerMappingConfig; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = ControllerClassNameHandlerMappingConfig.class) -public class ControllerClassNameHandlerMappingTest { - - @Autowired - private WebApplicationContext webAppContext; - private MockMvc mockMvc; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build(); - } - - @Test - public void whenControllerClassNameMapping_thenMappedOK() throws Exception { - mockMvc.perform(get("/welcome")).andExpect(status().isOk()).andExpect(view().name("test")).andDo(print()); - } -} diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleUrlMappingConfigTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleUrlMappingConfigTest.java deleted file mode 100644 index 0f83244738..0000000000 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleUrlMappingConfigTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.web.controller; - -import com.baeldung.spring.web.config.SimpleUrlHandlerMappingConfig; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = SimpleUrlHandlerMappingConfig.class) -public class SimpleUrlMappingConfigTest { - - @Autowired - private WebApplicationContext webAppContext; - private MockMvc mockMvc; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build(); - } - - @Test - public void whenSimpleUrlMapping_thenMappedOK() throws Exception { - mockMvc.perform(get("/simpleUrlWelcome")).andExpect(status().isOk()).andExpect(view().name("test")).andDo(print()); - } -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/BeanNameUrlHandlerMappingConfig.xml b/spring-mvc-java/src/test/resources/BeanNameUrlHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/BeanNameUrlHandlerMappingConfig.xml rename to spring-mvc-java/src/test/resources/BeanNameUrlHandlerMappingConfig.xml diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/ControllerClassNameHandlerMappingConfig.xml b/spring-mvc-java/src/test/resources/ControllerClassNameHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/ControllerClassNameHandlerMappingConfig.xml rename to spring-mvc-java/src/test/resources/ControllerClassNameHandlerMappingConfig.xml diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/HandlerMappingConfiguringPriorities.xml b/spring-mvc-java/src/test/resources/HandlerMappingConfiguringPriorities.xml similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/HandlerMappingConfiguringPriorities.xml rename to spring-mvc-java/src/test/resources/HandlerMappingConfiguringPriorities.xml diff --git a/spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/SimpleUrlHandlerMappingConfig.xml b/spring-mvc-java/src/test/resources/SimpleUrlHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/HandlerMapping/config/XML/SimpleUrlHandlerMappingConfig.xml rename to spring-mvc-java/src/test/resources/SimpleUrlHandlerMappingConfig.xml