1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.view; |
35 |
|
|
36 |
|
import org.junit.Test; |
37 |
|
import org.springframework.mock.web.MockHttpServletRequest; |
38 |
|
import org.springframework.mock.web.MockHttpServletResponse; |
39 |
|
import org.springframework.ui.ModelMap; |
40 |
|
import org.springframework.web.servlet.DispatcherServlet; |
41 |
|
import org.springframework.web.servlet.support.SessionFlashMapManager; |
42 |
|
|
43 |
|
import static org.junit.Assert.assertEquals; |
44 |
|
|
45 |
|
import info.magnolia.cms.beans.config.ServerConfiguration; |
46 |
|
import info.magnolia.cms.beans.config.URI2RepositoryManager; |
47 |
|
import info.magnolia.cms.i18n.DefaultI18nContentSupport; |
48 |
|
import info.magnolia.cms.i18n.I18nContentSupport; |
49 |
|
import info.magnolia.context.MgnlContext; |
50 |
|
import info.magnolia.link.AbsolutePathTransformer; |
51 |
|
import info.magnolia.link.LinkTransformerManager; |
52 |
|
import info.magnolia.repository.RepositoryConstants; |
53 |
|
import info.magnolia.test.ComponentsTestUtil; |
54 |
|
import info.magnolia.test.MgnlTestCase; |
55 |
|
import info.magnolia.test.mock.MockUtil; |
56 |
|
import info.magnolia.test.mock.MockWebContext; |
57 |
|
import info.magnolia.test.mock.jcr.MockNode; |
58 |
|
import info.magnolia.test.mock.jcr.MockSession; |
59 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@since |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (107) |
Complexity: 6 |
Complexity Density: 0.06 |
|
66 |
|
public class UuidRedirectViewResolverTest extends MgnlTestCase { |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
68 |
5 |
@Override... |
69 |
|
public void setUp() throws Exception { |
70 |
5 |
super.setUp(); |
71 |
5 |
((MockWebContext) MockUtil.getMockContext()).setContextPath(""); |
72 |
5 |
LinkTransformerManager linkTransformerManager = new LinkTransformerManager(); |
73 |
5 |
linkTransformerManager.addTransformer("absolute", new AbsolutePathTransformer()); |
74 |
5 |
linkTransformerManager.setAddContextPathToBrowserLinks(true); |
75 |
5 |
ComponentsTestUtil.setInstance(LinkTransformerManager.class, linkTransformerManager); |
76 |
5 |
ComponentsTestUtil.setInstance(URI2RepositoryManager.class, new URI2RepositoryManager()); |
77 |
5 |
ServerConfiguration serverConfiguration = new ServerConfiguration(); |
78 |
5 |
serverConfiguration.setDefaultExtension("html"); |
79 |
5 |
ComponentsTestUtil.setInstance(ServerConfiguration.class, serverConfiguration); |
80 |
5 |
ComponentsTestUtil.setInstance(I18nContentSupport.class, new DefaultI18nContentSupport()); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
public void testRedirect() throws Exception { |
85 |
|
|
86 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, "/foo/bar"); |
87 |
1 |
MockUtil.setSessionAndHierarchyManager(session); |
88 |
|
|
89 |
1 |
UuidRedirectViewResolver viewResolver = new UuidRedirectViewResolver(); |
90 |
|
|
91 |
1 |
viewResolver.afterPropertiesSet(); |
92 |
|
|
93 |
1 |
MockNode content = (MockNode) session.getNode("/foo/bar"); |
94 |
1 |
content.setIdentifier("abcd-1234"); |
95 |
|
|
96 |
1 |
UuidRedirectView view = (UuidRedirectView) viewResolver.resolveViewName("website:" + content.getIdentifier(), null); |
97 |
|
|
98 |
1 |
assertEquals("website", view.getWorkspace()); |
99 |
1 |
assertEquals("abcd-1234", view.getUuid()); |
100 |
|
|
101 |
1 |
MockHttpServletResponse response = new MockHttpServletResponse(); |
102 |
1 |
MockHttpServletRequest request = new MockHttpServletRequest(); |
103 |
1 |
request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
1 |
request.setContextPath("/contextpath"); |
109 |
1 |
((MockWebContext) MockUtil.getMockContext()).setContextPath(request.getContextPath()); |
110 |
1 |
response = new MockHttpServletResponse(); |
111 |
|
|
112 |
1 |
view.render(new ModelMap(), request, response); |
113 |
1 |
assertEquals("/contextpath/foo/bar.html", response.getRedirectedUrl()); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void testRedirectMainContent() throws Exception { |
118 |
|
|
119 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, "/foo/bar"); |
120 |
1 |
MockUtil.setSessionAndHierarchyManager(session); |
121 |
|
|
122 |
1 |
UuidRedirectViewResolver viewResolver = new UuidRedirectViewResolver(); |
123 |
|
|
124 |
1 |
viewResolver.afterPropertiesSet(); |
125 |
|
|
126 |
1 |
MockNode content = (MockNode) session.getNode("/foo/bar"); |
127 |
1 |
content.setIdentifier("abcd-1234"); |
128 |
|
|
129 |
1 |
MgnlContext.getAggregationState().setMainContentNode(content); |
130 |
|
|
131 |
1 |
UuidRedirectView view = (UuidRedirectView) viewResolver.resolveViewName("magnolia-redirect:main-content", null); |
132 |
|
|
133 |
1 |
assertEquals("website", view.getWorkspace()); |
134 |
1 |
assertEquals("abcd-1234", view.getUuid()); |
135 |
|
|
136 |
1 |
MockHttpServletResponse response = new MockHttpServletResponse(); |
137 |
1 |
MockHttpServletRequest request = new MockHttpServletRequest(); |
138 |
1 |
request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); |
139 |
1 |
view.render(new ModelMap(), request, response); |
140 |
1 |
assertEquals("/foo/bar.html", response.getRedirectedUrl()); |
141 |
|
|
142 |
|
|
143 |
1 |
request.setContextPath("/contextpath"); |
144 |
1 |
((MockWebContext) MockUtil.getMockContext()).setContextPath(request.getContextPath()); |
145 |
1 |
response = new MockHttpServletResponse(); |
146 |
|
|
147 |
1 |
view.render(new ModelMap(), request, response); |
148 |
1 |
assertEquals("/contextpath/foo/bar.html", response.getRedirectedUrl()); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
151 |
1 |
@Test... |
152 |
|
public void testRedirectCurrentContent() throws Exception { |
153 |
|
|
154 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, "/foo/bar"); |
155 |
1 |
MockUtil.setSessionAndHierarchyManager(session); |
156 |
|
|
157 |
1 |
UuidRedirectViewResolver viewResolver = new UuidRedirectViewResolver(); |
158 |
|
|
159 |
1 |
viewResolver.afterPropertiesSet(); |
160 |
|
|
161 |
1 |
MockNode content = (MockNode) session.getNode("/foo/bar"); |
162 |
1 |
content.setIdentifier("abcd-1234"); |
163 |
|
|
164 |
1 |
MgnlContext.getAggregationState().setCurrentContentNode(content); |
165 |
|
|
166 |
1 |
UuidRedirectView view = (UuidRedirectView) viewResolver.resolveViewName("magnolia-redirect:current-content", null); |
167 |
|
|
168 |
1 |
assertEquals("website", view.getWorkspace()); |
169 |
1 |
assertEquals("abcd-1234", view.getUuid()); |
170 |
|
|
171 |
1 |
MockHttpServletResponse response = new MockHttpServletResponse(); |
172 |
1 |
MockHttpServletRequest request = new MockHttpServletRequest(); |
173 |
1 |
request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); |
174 |
1 |
view.render(new ModelMap(), request, response); |
175 |
1 |
assertEquals("/foo/bar.html", response.getRedirectedUrl()); |
176 |
|
|
177 |
|
|
178 |
1 |
request.setContextPath("/contextpath"); |
179 |
1 |
((MockWebContext) MockUtil.getMockContext()).setContextPath(request.getContextPath()); |
180 |
1 |
response = new MockHttpServletResponse(); |
181 |
|
|
182 |
1 |
view.render(new ModelMap(), request, response); |
183 |
1 |
assertEquals("/contextpath/foo/bar.html", response.getRedirectedUrl()); |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
186 |
1 |
@Test... |
187 |
|
public void testRedirectWithModelAttributesExposed() throws Exception { |
188 |
|
|
189 |
1 |
UuidRedirectViewResolver viewResolver = new UuidRedirectViewResolver(); |
190 |
1 |
viewResolver.afterPropertiesSet(); |
191 |
|
|
192 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, "/foo/bar"); |
193 |
1 |
MockUtil.setSessionAndHierarchyManager(session); |
194 |
1 |
MockNode content = (MockNode) session.getNode("/foo/bar"); |
195 |
1 |
content.setIdentifier("abcd-1234"); |
196 |
|
|
197 |
1 |
UuidRedirectView view = (UuidRedirectView) viewResolver.resolveViewName("website:" + content.getIdentifier(), null); |
198 |
|
|
199 |
1 |
assertEquals("website", view.getWorkspace()); |
200 |
1 |
assertEquals("abcd-1234", view.getUuid()); |
201 |
|
|
202 |
1 |
MockHttpServletResponse response = new MockHttpServletResponse(); |
203 |
1 |
MockHttpServletRequest request = new MockHttpServletRequest(); |
204 |
1 |
request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); |
205 |
1 |
ModelMap model = new ModelMap(); |
206 |
1 |
model.put("attribute", "attributeValue"); |
207 |
1 |
view.render(model, request, response); |
208 |
|
|
209 |
1 |
assertEquals("/foo/bar.html?attribute=attributeValue", response.getRedirectedUrl()); |
210 |
|
} |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
212 |
1 |
@Test... |
213 |
|
public void testRedirectWithoutModelAttributesExposed() throws Exception { |
214 |
|
|
215 |
1 |
UuidRedirectViewResolver viewResolver = new UuidRedirectViewResolver(); |
216 |
1 |
viewResolver.setExposeModelAttributes(false); |
217 |
1 |
viewResolver.afterPropertiesSet(); |
218 |
|
|
219 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, "/foo/bar"); |
220 |
1 |
MockUtil.setSessionAndHierarchyManager(session); |
221 |
1 |
MockNode content = (MockNode) session.getNode("/foo/bar"); |
222 |
1 |
content.setIdentifier("abcd-1234"); |
223 |
|
|
224 |
1 |
UuidRedirectView view = (UuidRedirectView) viewResolver.resolveViewName("website:" + content.getIdentifier(), null); |
225 |
|
|
226 |
1 |
assertEquals("website", view.getWorkspace()); |
227 |
1 |
assertEquals("abcd-1234", view.getUuid()); |
228 |
|
|
229 |
1 |
MockHttpServletResponse response = new MockHttpServletResponse(); |
230 |
1 |
MockHttpServletRequest request = new MockHttpServletRequest(); |
231 |
1 |
request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); |
232 |
1 |
ModelMap model = new ModelMap(); |
233 |
1 |
model.put("attribute", "attributeValue"); |
234 |
1 |
view.render(model, request, response); |
235 |
|
|
236 |
1 |
assertEquals("/foo/bar.html", response.getRedirectedUrl()); |
237 |
|
} |
238 |
|
} |