Rename some urls.
This commit is contained in:
parent
c4bc953d1c
commit
877b8d2987
@ -38,14 +38,15 @@ public class RedirectController {
|
|||||||
return new RedirectView("redirectedUrl");
|
return new RedirectView("redirectedUrl");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/redirectWithForwardPrefix", method = RequestMethod.GET)
|
@RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
|
||||||
public ModelAndView redirectWithUsingForwardPrefix(final ModelMap model) {
|
public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
|
||||||
model.addAttribute("attribute", "redirectWithForwardPrefix");
|
model.addAttribute("attribute", "redirectWithForwardPrefix");
|
||||||
return new ModelAndView("forward:/redirectedUrl", model);
|
return new ModelAndView("forward:/redirectedUrl", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
|
@RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
|
||||||
public ModelAndView redirection(final ModelMap model, @ModelAttribute("flashAttribute") final Object flashAttribute) {
|
public ModelAndView redirection(final ModelMap model,
|
||||||
|
@ModelAttribute("flashAttribute") final Object flashAttribute) {
|
||||||
model.addAttribute("redirectionAttribute", flashAttribute);
|
model.addAttribute("redirectionAttribute", flashAttribute);
|
||||||
return new ModelAndView("redirection", model);
|
return new ModelAndView("redirection", model);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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">
|
<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">
|
||||||
|
|
||||||
<context:component-scan base-package="org.baeldung.web" />
|
<context:component-scan base-package="org.baeldung.web" />
|
||||||
|
|
||||||
|
<mvc:annotation-driven />
|
||||||
|
|
||||||
<mvc:annotation-driven />
|
|
||||||
|
|
||||||
<bean
|
<bean
|
||||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
|
class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
|
||||||
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
|
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
|
||||||
@ -14,15 +17,15 @@
|
|||||||
<property name="order" value="0" />
|
<property name="order" value="0" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="multipartResolver"
|
<bean id="multipartResolver"
|
||||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||||
<!-- max upload size in bytes -->
|
<!-- max upload size in bytes -->
|
||||||
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
|
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
|
||||||
|
|
||||||
<!-- max size of file in memory (in bytes) -->
|
<!-- max size of file in memory (in bytes) -->
|
||||||
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
|
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
|
||||||
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@ -46,26 +46,36 @@ public class RedirectControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
|
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
|
||||||
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
|
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(view().name("redirect:/redirectedUrl"))
|
||||||
|
.andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
|
||||||
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
|
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
|
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
|
||||||
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
|
throws Exception {
|
||||||
|
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
|
||||||
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes")))
|
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes")))
|
||||||
.andExpect(model().attribute("flashAttribute", is(nullValue())))
|
.andExpect(model().attribute("flashAttribute", is(nullValue())))
|
||||||
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
|
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
|
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
|
||||||
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
|
throws Exception {
|
||||||
|
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(model().attribute("attribute", is("redirectWithRedirectView")))
|
||||||
|
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
|
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
|
||||||
mockMvc.perform(get("/redirectWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
|
mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk())
|
||||||
|
.andExpect(view().name("forward:/redirectedUrl"))
|
||||||
|
.andExpect(model().attribute("attribute", is("redirectWithForwardPrefix")))
|
||||||
|
.andExpect(forwardedUrl("/redirectedUrl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user