Skip to content

Commit 23bf5a3

Browse files
author
alex-semenyuk
committed
Fix formatting files
1 parent 877b8d2 commit 23bf5a3

File tree

5 files changed

+128
-142
lines changed

5 files changed

+128
-142
lines changed

spring-rest/src/main/java/org/baeldung/web/controller/redirect/RedirectController.java

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,40 @@
1313
@RequestMapping("/")
1414
public class RedirectController {
1515

16-
@RequestMapping(value = "/redirectWithXMLConfig", method = RequestMethod.GET)
17-
public ModelAndView redirectWithUsingXMLConfig(final ModelMap model) {
18-
model.addAttribute("attribute", "redirectWithXMLConfig");
19-
return new ModelAndView("RedirectedUrl", model);
20-
}
21-
22-
@RequestMapping(value = "/redirectWithRedirectPrefix", method = RequestMethod.GET)
23-
public ModelAndView redirectWithUsingRedirectPrefix(final ModelMap model) {
24-
model.addAttribute("attribute", "redirectWithRedirectPrefix");
25-
return new ModelAndView("redirect:/redirectedUrl", model);
26-
}
27-
28-
@RequestMapping(value = "/redirectWithRedirectAttributes", method = RequestMethod.GET)
29-
public RedirectView redirectWithRedirectAttributes(final RedirectAttributes redirectAttributes) {
30-
redirectAttributes.addFlashAttribute("flashAttribute", "redirectWithRedirectAttributes");
31-
redirectAttributes.addAttribute("attribute", "redirectWithRedirectAttributes");
32-
return new RedirectView("redirectedUrl");
33-
}
34-
35-
@RequestMapping(value = "/redirectWithRedirectView", method = RequestMethod.GET)
36-
public RedirectView redirectWithUsingRedirectView(final ModelMap model) {
37-
model.addAttribute("attribute", "redirectWithRedirectView");
38-
return new RedirectView("redirectedUrl");
39-
}
40-
41-
@RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
42-
public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
43-
model.addAttribute("attribute", "redirectWithForwardPrefix");
44-
return new ModelAndView("forward:/redirectedUrl", model);
45-
}
46-
47-
@RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
48-
public ModelAndView redirection(final ModelMap model,
49-
@ModelAttribute("flashAttribute") final Object flashAttribute) {
50-
model.addAttribute("redirectionAttribute", flashAttribute);
51-
return new ModelAndView("redirection", model);
52-
}
16+
@RequestMapping(value = "/redirectWithXMLConfig", method = RequestMethod.GET)
17+
public ModelAndView redirectWithUsingXMLConfig(final ModelMap model) {
18+
model.addAttribute("attribute", "redirectWithXMLConfig");
19+
return new ModelAndView("RedirectedUrl", model);
20+
}
21+
22+
@RequestMapping(value = "/redirectWithRedirectPrefix", method = RequestMethod.GET)
23+
public ModelAndView redirectWithUsingRedirectPrefix(final ModelMap model) {
24+
model.addAttribute("attribute", "redirectWithRedirectPrefix");
25+
return new ModelAndView("redirect:/redirectedUrl", model);
26+
}
27+
28+
@RequestMapping(value = "/redirectWithRedirectAttributes", method = RequestMethod.GET)
29+
public RedirectView redirectWithRedirectAttributes(final RedirectAttributes redirectAttributes) {
30+
redirectAttributes.addFlashAttribute("flashAttribute", "redirectWithRedirectAttributes");
31+
redirectAttributes.addAttribute("attribute", "redirectWithRedirectAttributes");
32+
return new RedirectView("redirectedUrl");
33+
}
34+
35+
@RequestMapping(value = "/redirectWithRedirectView", method = RequestMethod.GET)
36+
public RedirectView redirectWithUsingRedirectView(final ModelMap model) {
37+
model.addAttribute("attribute", "redirectWithRedirectView");
38+
return new RedirectView("redirectedUrl");
39+
}
40+
41+
@RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
42+
public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
43+
model.addAttribute("attribute", "redirectWithForwardPrefix");
44+
return new ModelAndView("forward:/redirectedUrl", model);
45+
}
46+
47+
@RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
48+
public ModelAndView redirection(final ModelMap model, @ModelAttribute("flashAttribute") final Object flashAttribute) {
49+
model.addAttribute("redirectionAttribute", flashAttribute);
50+
return new ModelAndView("redirection", model);
51+
}
5352
}

spring-rest/src/main/webapp/WEB-INF/api-servlet.xml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<beans xmlns="http://www.springframework.org/schema/beans"
3-
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:context="http://www.springframework.org/schema/context"
5-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
5+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
6+
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"
7+
>
68

7-
<context:component-scan base-package="org.baeldung.web" />
9+
<context:component-scan base-package="org.baeldung.web" />
810

9-
<mvc:annotation-driven />
11+
<mvc:annotation-driven />
1012

11-
<bean
12-
class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
13-
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
14-
<property name="location">
15-
<value>/WEB-INF/spring-views.xml</value>
16-
</property>
17-
<property name="order" value="0" />
18-
</bean>
13+
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
14+
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
15+
<property name="location">
16+
<value>/WEB-INF/spring-views.xml</value>
17+
</property>
18+
<property name="order" value="0" />
19+
</bean>
1920

20-
<bean id="multipartResolver"
21-
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
22-
<!-- max upload size in bytes -->
23-
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
21+
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
22+
<!-- max upload size in bytes -->
23+
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
2424

25-
<!-- max size of file in memory (in bytes) -->
26-
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
25+
<!-- max size of file in memory (in bytes) -->
26+
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
2727

28-
</bean>
28+
</bean>
29+
30+
31+
</beans>
2932

3033

31-
</beans>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<beans xmlns="http://www.springframework.org/schema/beans"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://www.springframework.org/schema/beans
4-
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
1+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://www.springframework.org/schema/beans
3+
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
4+
>
55

6-
<bean id="RedirectedUrl" class="org.springframework.web.servlet.view.RedirectView">
7-
<property name="url" value="redirectedUrl" />
8-
</bean>
6+
<bean id="RedirectedUrl" class="org.springframework.web.servlet.view.RedirectView">
7+
<property name="url" value="redirectedUrl" />
8+
</bean>
99

1010
</beans>
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
4-
xsi:schemaLocation="
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
3+
xsi:schemaLocation="
54
http://java.sun.com/xml/ns/javaee
6-
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
7-
id="WebApp_ID" version="3.0">
5+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"
6+
>
87

9-
<display-name>Spring MVC Application</display-name>
8+
<display-name>Spring MVC Application</display-name>
109

11-
<!-- Spring root -->
12-
<context-param>
13-
<param-name>contextClass</param-name>
14-
<param-value>
10+
<!-- Spring root -->
11+
<context-param>
12+
<param-name>contextClass</param-name>
13+
<param-value>
1514
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
1615
</param-value>
17-
</context-param>
18-
<context-param>
19-
<param-name>contextConfigLocation</param-name>
20-
<param-value>org.baeldung.config</param-value>
21-
</context-param>
16+
</context-param>
17+
<context-param>
18+
<param-name>contextConfigLocation</param-name>
19+
<param-value>org.baeldung.config</param-value>
20+
</context-param>
2221

23-
<listener>
24-
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
25-
</listener>
22+
<listener>
23+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
24+
</listener>
2625

27-
<!-- Spring child -->
28-
<servlet>
29-
<servlet-name>api</servlet-name>
30-
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
31-
<load-on-startup>1</load-on-startup>
32-
</servlet>
33-
<servlet-mapping>
34-
<servlet-name>api</servlet-name>
35-
<url-pattern>/</url-pattern>
36-
</servlet-mapping>
26+
<!-- Spring child -->
27+
<servlet>
28+
<servlet-name>api</servlet-name>
29+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
30+
<load-on-startup>1</load-on-startup>
31+
</servlet>
32+
<servlet-mapping>
33+
<servlet-name>api</servlet-name>
34+
<url-pattern>/</url-pattern>
35+
</servlet-mapping>
3736

38-
<welcome-file-list>
39-
<welcome-file />
40-
</welcome-file-list>
37+
<welcome-file-list>
38+
<welcome-file />
39+
</welcome-file-list>
4140

42-
</web-app>
41+
</web-app>

spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,42 @@
2626
@WebAppConfiguration
2727
public class RedirectControllerTest {
2828

29-
private MockMvc mockMvc;
29+
private MockMvc mockMvc;
3030

31-
@Autowired
32-
protected WebApplicationContext wac;
31+
@Autowired
32+
protected WebApplicationContext wac;
3333

34-
@Before
35-
public void setup() {
36-
mockMvc = webAppContextSetup(wac).build();
37-
}
34+
@Before
35+
public void setup() {
36+
mockMvc = webAppContextSetup(wac).build();
37+
}
3838

39-
@Test
40-
public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
41-
mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection())
42-
.andExpect(view().name("RedirectedUrl"))
43-
.andExpect(model().attribute("attribute", is("redirectWithXMLConfig")))
44-
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig"));
45-
}
39+
@Test
40+
public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
41+
mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithXMLConfig")))
42+
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig"));
43+
}
4644

47-
@Test
48-
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
49-
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection())
50-
.andExpect(view().name("redirect:/redirectedUrl"))
51-
.andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
52-
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
53-
}
45+
@Test
46+
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
47+
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
48+
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
49+
}
5450

55-
@Test
56-
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
57-
throws Exception {
58-
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection())
59-
.andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
60-
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes")))
61-
.andExpect(model().attribute("flashAttribute", is(nullValue())))
62-
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
63-
}
51+
@Test
52+
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
53+
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
54+
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", is(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
55+
}
6456

65-
@Test
66-
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
67-
throws Exception {
68-
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection())
69-
.andExpect(model().attribute("attribute", is("redirectWithRedirectView")))
70-
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
71-
}
57+
@Test
58+
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
59+
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
60+
}
7261

73-
@Test
74-
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
75-
mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk())
76-
.andExpect(view().name("forward:/redirectedUrl"))
77-
.andExpect(model().attribute("attribute", is("redirectWithForwardPrefix")))
78-
.andExpect(forwardedUrl("/redirectedUrl"));
79-
}
62+
@Test
63+
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
64+
mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
65+
}
8066

8167
}

0 commit comments

Comments
 (0)