Skip to content

Commit 877b8d2

Browse files
author
alex-semenyuk
committed
Rename some urls.
1 parent c4bc953 commit 877b8d2

3 files changed

Lines changed: 38 additions & 24 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ public RedirectView redirectWithUsingRedirectView(final ModelMap model) {
3838
return new RedirectView("redirectedUrl");
3939
}
4040

41-
@RequestMapping(value = "/redirectWithForwardPrefix", method = RequestMethod.GET)
42-
public ModelAndView redirectWithUsingForwardPrefix(final ModelMap model) {
41+
@RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
42+
public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
4343
model.addAttribute("attribute", "redirectWithForwardPrefix");
4444
return new ModelAndView("forward:/redirectedUrl", model);
4545
}
4646

4747
@RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
48-
public ModelAndView redirection(final ModelMap model, @ModelAttribute("flashAttribute") final Object flashAttribute) {
48+
public ModelAndView redirection(final ModelMap model,
49+
@ModelAttribute("flashAttribute") final Object flashAttribute) {
4950
model.addAttribute("redirectionAttribute", flashAttribute);
5051
return new ModelAndView("redirection", model);
5152
}
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
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" xmlns:context="http://www.springframework.org/schema/context" 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"
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">
36

4-
<context:component-scan base-package="org.baeldung.web" />
7+
<context:component-scan base-package="org.baeldung.web" />
8+
9+
<mvc:annotation-driven />
510

6-
<mvc:annotation-driven />
7-
811
<bean
912
class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
1013
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
@@ -14,15 +17,15 @@
1417
<property name="order" value="0" />
1518
</bean>
1619

17-
<bean id="multipartResolver"
18-
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
19-
<!-- max upload size in bytes -->
20-
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
21-
22-
<!-- max size of file in memory (in bytes) -->
23-
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
24-
25-
</bean>
26-
27-
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 -->
24+
25+
<!-- max size of file in memory (in bytes) -->
26+
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
27+
28+
</bean>
29+
30+
2831
</beans>

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,36 @@ public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirect
4646

4747
@Test
4848
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
49-
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
49+
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection())
50+
.andExpect(view().name("redirect:/redirectedUrl"))
51+
.andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
5052
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
5153
}
5254

5355
@Test
54-
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
55-
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
56+
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
57+
throws Exception {
58+
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection())
59+
.andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
5660
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes")))
5761
.andExpect(model().attribute("flashAttribute", is(nullValue())))
5862
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
5963
}
6064

6165
@Test
62-
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
63-
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
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"));
6471
}
6572

6673
@Test
6774
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
68-
mockMvc.perform(get("/redirectWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
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"));
6979
}
7080

7181
}

0 commit comments

Comments
 (0)