1 | package edu.iu.uis.sit.portal.portlet.admin.web; |
2 | |
3 | import java.sql.Timestamp; |
4 | import java.util.ArrayList; |
5 | import java.util.Iterator; |
6 | import java.util.List; |
7 | import java.util.Map; |
8 | |
9 | import org.springframework.mock.web.portlet.MockPortletRequest; |
10 | import org.springframework.mock.web.portlet.MockRenderRequest; |
11 | import org.springframework.mock.web.portlet.MockRenderResponse; |
12 | import org.springframework.validation.BindException; |
13 | import org.springframework.validation.Errors; |
14 | import org.springframework.web.portlet.ModelAndView; |
15 | |
16 | import edu.iu.uis.sit.portal.PersistenceBrokerAbstractTransactionalDataSourceSpringContextTests; |
17 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortalConfig; |
18 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortalSupport; |
19 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletApplication; |
20 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletConfig; |
21 | import edu.iu.uis.sit.portal.portlet.admin.services.AdminService; |
22 | import edu.iu.uis.sit.portal.portlet.utility.Constants; |
23 | import edu.iu.uis.sit.portal.user.User; |
24 | import edu.iu.uis.sit.portal.user.domain.OneStartUser; |
25 | import edu.iu.uis.sit.portal.user.service.UserService; |
26 | |
27 | public class AllPortletApplicationControllersTest extends PersistenceBrokerAbstractTransactionalDataSourceSpringContextTests { |
28 | |
29 | private AdminService adminService; |
30 | |
31 | private UserService userService; |
32 | |
33 | private PortletApplicationValidator portletApplicationValidator; |
34 | |
35 | private PortletApplicationViewController portletApplicationViewController; |
36 | |
37 | private PortletApplicationDeleteController portletApplicationDeleteController; |
38 | |
39 | private PortletApplicationController portletApplicationController; |
40 | |
41 | private OneStartUser oneStartUser; |
42 | |
43 | private PortalConfig portalConfig; |
44 | |
45 | private PortletApplication portletApplication; |
46 | |
47 | protected void onSetUpInTransaction() throws Exception { |
48 | OneStartUser oneStartUser = new OneStartUser(); |
49 | oneStartUser.setEmplId("01234567890"); |
50 | oneStartUser.setUserName("jdoe"); |
51 | oneStartUser.setLastLoginDate(new Timestamp(System.currentTimeMillis())); |
52 | getUserService().saveOneStartUser(oneStartUser); |
53 | this.oneStartUser = oneStartUser; |
54 | |
55 | PortalConfig portalConfig = getAdminService().getPortalConfig(); |
56 | if (portalConfig == null) { |
57 | portalConfig = new PortalConfig(); |
58 | portalConfig.setPortalVersion("1.1.0-BETA1"); |
59 | portalConfig.setContainerName("Pluto Portal Driver"); |
60 | portalConfig.setPortalName("pluto-portal-driver"); |
61 | |
62 | List supports = new ArrayList(); |
63 | PortalSupport support = new PortalSupport(); |
64 | support.setPortalConfig(portalConfig); |
65 | support.setSupportName("view"); |
66 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
67 | supports.add(support); |
68 | |
69 | support = new PortalSupport(); |
70 | support.setPortalConfig(portalConfig); |
71 | support.setSupportName("edit"); |
72 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
73 | supports.add(support); |
74 | |
75 | support = new PortalSupport(); |
76 | support.setPortalConfig(portalConfig); |
77 | support.setSupportName("help"); |
78 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
79 | supports.add(support); |
80 | |
81 | support = new PortalSupport(); |
82 | support.setPortalConfig(portalConfig); |
83 | support.setSupportName("config"); |
84 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
85 | supports.add(support); |
86 | |
87 | support = new PortalSupport(); |
88 | support.setPortalConfig(portalConfig); |
89 | support.setSupportName("normal"); |
90 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
91 | supports.add(support); |
92 | |
93 | support = new PortalSupport(); |
94 | support.setPortalConfig(portalConfig); |
95 | support.setSupportName("maximized"); |
96 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
97 | supports.add(support); |
98 | |
99 | support = new PortalSupport(); |
100 | support.setPortalConfig(portalConfig); |
101 | support.setSupportName("minimized"); |
102 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
103 | supports.add(support); |
104 | |
105 | List portletApplications = new ArrayList(); |
106 | PortletApplication application = new PortletApplication(); |
107 | application.setContextPath("/my-dev"); |
108 | |
109 | List portletConfigs = new ArrayList(); |
110 | PortletConfig config = new PortletConfig(); |
111 | config.setPortletApplication(application); |
112 | config.setPortletName("AdminPortlet"); |
113 | portletConfigs.add(config); |
114 | |
115 | config = new PortletConfig(); |
116 | config.setPortletApplication(application); |
117 | config.setPortletName("PublishingPortlet"); |
118 | portletConfigs.add(config); |
119 | |
120 | config = new PortletConfig(); |
121 | config.setPortletApplication(application); |
122 | config.setPortletName("GroupsPortlet"); |
123 | portletConfigs.add(config); |
124 | |
125 | config = new PortletConfig(); |
126 | config.setPortletApplication(application); |
127 | config.setPortletName("ExamplePortlet"); |
128 | portletConfigs.add(config); |
129 | |
130 | application.setPortletConfigs(portletConfigs); |
131 | portletApplications.add(application); |
132 | |
133 | application = new PortletApplication(); |
134 | application.setContextPath("/onestartportlets"); |
135 | |
136 | portletConfigs = new ArrayList(); |
137 | config = new PortletConfig(); |
138 | config.setPortletApplication(application); |
139 | config.setPortletName("IframePortlet"); |
140 | portletConfigs.add(config); |
141 | |
142 | config = new PortletConfig(); |
143 | config.setPortletApplication(application); |
144 | config.setPortletName("RSSPortlet"); |
145 | portletConfigs.add(config); |
146 | |
147 | application.setPortletConfigs(portletConfigs); |
148 | portletApplications.add(application); |
149 | |
150 | application = new PortletApplication(); |
151 | application.setContextPath("/ccf-dev"); |
152 | |
153 | portletConfigs = new ArrayList(); |
154 | config = new PortletConfig(); |
155 | config.setPortletApplication(application); |
156 | config.setPortletName("ClassifiedsPortlet"); |
157 | portletConfigs.add(config); |
158 | |
159 | application.setPortletConfigs(portletConfigs); |
160 | portletApplications.add(application); |
161 | |
162 | application = new PortletApplication(); |
163 | application.setContextPath("/SpringPortlets"); |
164 | |
165 | portletConfigs = new ArrayList(); |
166 | config = new PortletConfig(); |
167 | config.setPortletApplication(application); |
168 | config.setPortletName("books"); |
169 | portletConfigs.add(config); |
170 | |
171 | portletConfigs = new ArrayList(); |
172 | config = new PortletConfig(); |
173 | config.setPortletApplication(application); |
174 | config.setPortletName("exceptions"); |
175 | portletConfigs.add(config); |
176 | |
177 | portletConfigs = new ArrayList(); |
178 | config = new PortletConfig(); |
179 | config.setPortletApplication(application); |
180 | config.setPortletName("mode"); |
181 | portletConfigs.add(config); |
182 | |
183 | portletConfigs = new ArrayList(); |
184 | config = new PortletConfig(); |
185 | config.setPortletApplication(application); |
186 | config.setPortletName("redirect"); |
187 | portletConfigs.add(config); |
188 | |
189 | portletConfigs = new ArrayList(); |
190 | config = new PortletConfig(); |
191 | config.setPortletApplication(application); |
192 | config.setPortletName("upload"); |
193 | portletConfigs.add(config); |
194 | |
195 | portletConfigs = new ArrayList(); |
196 | config = new PortletConfig(); |
197 | config.setPortletApplication(application); |
198 | config.setPortletName("helloworld"); |
199 | portletConfigs.add(config); |
200 | |
201 | application.setPortletConfigs(portletConfigs); |
202 | portletApplications.add(application); |
203 | |
204 | getAdminService().savePortalConfig(portalConfig); |
205 | } |
206 | PortletApplication application2 = new PortletApplication(); |
207 | application2.setContextPath("/testing"); |
208 | application2.setPortalConfig(portalConfig); |
209 | |
210 | getAdminService().savePortletApplication(portalConfig, application2); |
211 | this.portletApplication = application2; |
212 | this.portalConfig = portalConfig; |
213 | } |
214 | |
215 | private User getUser() { |
216 | String userName = "jdoe"; |
217 | String firstName = "John"; |
218 | String lastName = "Doe"; |
219 | String emailAddress = "jdoe@university.edu"; |
220 | String campusCode = "BL"; |
221 | List groups = new ArrayList(); |
222 | groups.add("group1"); |
223 | groups.add("group2"); |
224 | groups.add("group3"); |
225 | |
226 | OneStartUser oneStartUser = getUserService().findOneStartUserByUserName(userName); |
227 | return new User(oneStartUser, lastName, firstName, emailAddress, campusCode, groups); |
228 | } |
229 | |
230 | public void testPortletApplicationValidatorValidate() { |
231 | try { |
232 | WebPortalConfig webPortalConfig = new WebPortalConfig(); |
233 | Errors errors = new BindException(webPortalConfig, "webPortalConfig"); |
234 | getPortletApplicationValidator().validate(webPortalConfig, errors); |
235 | assertTrue("There should be errors from the validation. Required field contextPath.", errors.hasErrors()); |
236 | |
237 | } catch (Exception e) { |
238 | assertTrue("An error occured. " + e.toString(), false); |
239 | } |
240 | } |
241 | |
242 | public void testPortletApplicationOnSubmitAction() { |
243 | try { |
244 | WebPortalConfig webPortalConfig = new WebPortalConfig(portalConfig); |
245 | portletApplication.setContextPath("/change"); |
246 | webPortalConfig.setPortletApplication(portletApplication); |
247 | getPortletApplicationController().onSubmitAction(webPortalConfig); |
248 | assertEquals("Portlet application should have been updated.", "/change", getAdminService().findPortletApplicationById(portletApplication.getPortletApplicationId()).getContextPath()); |
249 | } catch (Exception e) { |
250 | assertTrue("An error occured. " + e.toString(), false); |
251 | } |
252 | } |
253 | |
254 | public void testPortletApplicationOnSubmitRender() { |
255 | try { |
256 | WebPortalConfig webPortalConfig = new WebPortalConfig(portalConfig); |
257 | ModelAndView modelAndView = getPortletApplicationController().onSubmitRender(webPortalConfig); |
258 | |
259 | assertNotNull("ModelAndView does not contain content.", modelAndView.getModel()); |
260 | if (modelAndView.getModel() != null) { |
261 | assertTrue("ModelAndView does not contain a portlet applications.", modelAndView.getModel().containsKey("portletApplications")); |
262 | for (Iterator iter = modelAndView.getModel().entrySet().iterator(); iter.hasNext();) { |
263 | Map.Entry entry = (Map.Entry) iter.next(); |
264 | if (entry.getKey().equals("portletApplications")) { |
265 | assertTrue("There should be at least 1 portlet application.", ((List) entry.getValue()).size() > 0); |
266 | } |
267 | } |
268 | } |
269 | } catch (Exception e) { |
270 | assertTrue("An error occured. " + e.toString(), false); |
271 | } |
272 | } |
273 | |
274 | public void testPortletApplicationFormBackingObject() { |
275 | MockPortletRequest portletRequest = new MockPortletRequest(); |
276 | |
277 | try { |
278 | Object object = getPortletApplicationController().formBackingObject(portletRequest); |
279 | assertTrue("Command object should be of type WebPortalConfig.", object instanceof WebPortalConfig); |
280 | |
281 | WebPortalConfig webPortalConfig = (WebPortalConfig) object; |
282 | assertNotNull("WebPortalConfig should be present.", webPortalConfig); |
283 | assertNull("Portlet Application should be empty because we are creating a new one.", webPortalConfig.getPortletApplication().getContextPath()); |
284 | |
285 | portletRequest.addParameter("portletApplicationId", portletApplication.getPortletApplicationId().toString()); |
286 | object = getPortletApplicationController().formBackingObject(portletRequest); |
287 | |
288 | webPortalConfig = (WebPortalConfig) object; |
289 | assertEquals("Portlet Application context should be /testing.", "/testing", webPortalConfig.getPortletApplication().getContextPath()); |
290 | } catch (Exception e) { |
291 | assertTrue("An error occured. " + e.toString(), false); |
292 | } |
293 | } |
294 | |
295 | public void testPortletApplicationDeleteOnSubmitRender() { |
296 | try { |
297 | ModelAndView modelAndView = getPortletApplicationDeleteController().onSubmitRender(portletApplication); |
298 | |
299 | assertNotNull("ModelAndView does not contain content.", modelAndView.getModel()); |
300 | if (modelAndView.getModel() != null) { |
301 | assertTrue("ModelAndView does not contain a portlet applications.", modelAndView.getModel().containsKey("portletApplications")); |
302 | for (Iterator iter = modelAndView.getModel().entrySet().iterator(); iter.hasNext();) { |
303 | Map.Entry entry = (Map.Entry) iter.next(); |
304 | if (entry.getKey().equals("portletApplications")) { |
305 | assertTrue("There may be 0 or more portlet application.", ((List) entry.getValue()).size() >= 0); |
306 | } |
307 | } |
308 | } |
309 | } catch (Exception e) { |
310 | assertTrue("An error occured. " + e.toString(), false); |
311 | } |
312 | } |
313 | |
314 | public void testPortletApplicationDeleteOnSubmitAction() { |
315 | try { |
316 | getPortletApplicationDeleteController().onSubmitAction(portletApplication); |
317 | assertNull("Portlet Application should have been deleted.", getAdminService().findPortletApplicationById(portletApplication.getPortletApplicationId())); |
318 | } catch (Exception e) { |
319 | assertTrue("An error occured. " + e.toString(), false); |
320 | } |
321 | } |
322 | |
323 | public void testPortletApplicationDeleteFormBackingObject() { |
324 | MockPortletRequest portletRequest = new MockPortletRequest(); |
325 | |
326 | try { |
327 | Object object = getPortletApplicationDeleteController().formBackingObject(portletRequest); |
328 | assertTrue("Command object should be of type PortletApplication.", object instanceof PortletApplication); |
329 | |
330 | PortletApplication portletApplication = (PortletApplication) object; |
331 | assertNull("Portlet application should be a new empty object.", portletApplication.getPortletApplicationId()); |
332 | |
333 | portletRequest.addParameter("portletApplicationId", this.portletApplication.getPortletApplicationId().toString()); |
334 | |
335 | object = getPortletApplicationDeleteController().formBackingObject(portletRequest); |
336 | assertTrue("Command object should be of type PortletApplication.", object instanceof PortletApplication); |
337 | |
338 | PortletApplication found = (PortletApplication) object; |
339 | assertEquals("Portlet Application id is incorrect.", this.portletApplication.getPortletApplicationId(), found.getPortletApplicationId()); |
340 | |
341 | } catch (Exception e) { |
342 | assertTrue("An error occured. " + e.toString(), false); |
343 | } |
344 | } |
345 | |
346 | public void testPortletApplicationViewHandleRenderRequestInternal() { |
347 | MockRenderRequest renderRequest = new MockRenderRequest(); |
348 | MockRenderResponse renderResponse = new MockRenderResponse(); |
349 | try { |
350 | ModelAndView modelAndView = getPortletApplicationViewController().handleRenderRequestInternal(renderRequest, renderResponse); |
351 | |
352 | assertNotNull("ModelAndView does not contain content.", modelAndView.getModel()); |
353 | if (modelAndView.getModel() != null) { |
354 | assertTrue("ModelAndView does not contain a portlet applications.", modelAndView.getModel().containsKey("portletApplications")); |
355 | for (Iterator iter = modelAndView.getModel().entrySet().iterator(); iter.hasNext();) { |
356 | Map.Entry entry = (Map.Entry) iter.next(); |
357 | if (entry.getKey().equals("portletApplications")) { |
358 | assertTrue("There should be at least 1 portlet application.", ((List) entry.getValue()).size() > 0); |
359 | } |
360 | } |
361 | } |
362 | } catch (Exception e) { |
363 | assertTrue("An error occured. " + e.toString(), false); |
364 | } |
365 | } |
366 | |
367 | public OneStartUser getOneStartUser() { |
368 | return oneStartUser; |
369 | } |
370 | |
371 | public UserService getUserService() { |
372 | return userService; |
373 | } |
374 | |
375 | public void setUserService(UserService userService) { |
376 | this.userService = userService; |
377 | } |
378 | |
379 | public AdminService getAdminService() { |
380 | return adminService; |
381 | } |
382 | |
383 | public void setAdminService(AdminService adminService) { |
384 | this.adminService = adminService; |
385 | } |
386 | |
387 | public PortletApplicationController getPortletApplicationController() { |
388 | return portletApplicationController; |
389 | } |
390 | |
391 | public void setPortletApplicationController(PortletApplicationController portletApplicationController) { |
392 | this.portletApplicationController = portletApplicationController; |
393 | } |
394 | |
395 | public PortletApplicationDeleteController getPortletApplicationDeleteController() { |
396 | return portletApplicationDeleteController; |
397 | } |
398 | |
399 | public void setPortletApplicationDeleteController(PortletApplicationDeleteController portletApplicationDeleteController) { |
400 | this.portletApplicationDeleteController = portletApplicationDeleteController; |
401 | } |
402 | |
403 | public PortletApplicationValidator getPortletApplicationValidator() { |
404 | return portletApplicationValidator; |
405 | } |
406 | |
407 | public void setPortletApplicationValidator(PortletApplicationValidator portletApplicationValidator) { |
408 | this.portletApplicationValidator = portletApplicationValidator; |
409 | } |
410 | |
411 | public PortletApplicationViewController getPortletApplicationViewController() { |
412 | return portletApplicationViewController; |
413 | } |
414 | |
415 | public void setPortletApplicationViewController(PortletApplicationViewController portletApplicationViewController) { |
416 | this.portletApplicationViewController = portletApplicationViewController; |
417 | } |
418 | |
419 | } |