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.List; |
6 | |
7 | import org.springframework.mock.web.portlet.MockPortletRequest; |
8 | import org.springframework.mock.web.portlet.MockRenderRequest; |
9 | import org.springframework.mock.web.portlet.MockRenderResponse; |
10 | import org.springframework.validation.BindException; |
11 | import org.springframework.validation.Errors; |
12 | import org.springframework.web.portlet.ModelAndView; |
13 | |
14 | import edu.iu.uis.sit.portal.PersistenceBrokerAbstractTransactionalDataSourceSpringContextTests; |
15 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortalConfig; |
16 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortalSupport; |
17 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletApplication; |
18 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletConfig; |
19 | import edu.iu.uis.sit.portal.portlet.admin.services.AdminService; |
20 | import edu.iu.uis.sit.portal.portlet.utility.Constants; |
21 | import edu.iu.uis.sit.portal.user.User; |
22 | import edu.iu.uis.sit.portal.user.domain.OneStartUser; |
23 | import edu.iu.uis.sit.portal.user.service.UserService; |
24 | |
25 | public class AllPortalConfigControllersTest extends PersistenceBrokerAbstractTransactionalDataSourceSpringContextTests { |
26 | |
27 | private AdminService adminService; |
28 | |
29 | private UserService userService; |
30 | |
31 | private PortalConfigValidator portalConfigValidator; |
32 | |
33 | private PortalConfigViewController portalConfigViewController; |
34 | |
35 | private PortalConfigController portalConfigController; |
36 | |
37 | private OneStartUser oneStartUser; |
38 | |
39 | private PortalConfig portalConfig; |
40 | |
41 | protected void onSetUpInTransaction() throws Exception { |
42 | OneStartUser oneStartUser = new OneStartUser(); |
43 | oneStartUser.setEmplId("01234567890"); |
44 | oneStartUser.setUserName("jdoe"); |
45 | oneStartUser.setLastLoginDate(new Timestamp(System.currentTimeMillis())); |
46 | getUserService().saveOneStartUser(oneStartUser); |
47 | this.oneStartUser = oneStartUser; |
48 | |
49 | PortalConfig portalConfig = getAdminService().getPortalConfig(); |
50 | if (portalConfig == null) { |
51 | portalConfig = new PortalConfig(); |
52 | portalConfig.setPortalVersion("1.1.0-BETA1"); |
53 | portalConfig.setContainerName("Pluto Portal Driver"); |
54 | portalConfig.setPortalName("pluto-portal-driver"); |
55 | |
56 | List supports = new ArrayList(); |
57 | PortalSupport support = new PortalSupport(); |
58 | support.setPortalConfig(portalConfig); |
59 | support.setSupportName("view"); |
60 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
61 | supports.add(support); |
62 | |
63 | support = new PortalSupport(); |
64 | support.setPortalConfig(portalConfig); |
65 | support.setSupportName("edit"); |
66 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
67 | supports.add(support); |
68 | |
69 | support = new PortalSupport(); |
70 | support.setPortalConfig(portalConfig); |
71 | support.setSupportName("help"); |
72 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
73 | supports.add(support); |
74 | |
75 | support = new PortalSupport(); |
76 | support.setPortalConfig(portalConfig); |
77 | support.setSupportName("config"); |
78 | support.setSupportType(Constants.PORTLET_MODE_SUPPORT); |
79 | supports.add(support); |
80 | |
81 | support = new PortalSupport(); |
82 | support.setPortalConfig(portalConfig); |
83 | support.setSupportName("normal"); |
84 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
85 | supports.add(support); |
86 | |
87 | support = new PortalSupport(); |
88 | support.setPortalConfig(portalConfig); |
89 | support.setSupportName("maximized"); |
90 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
91 | supports.add(support); |
92 | |
93 | support = new PortalSupport(); |
94 | support.setPortalConfig(portalConfig); |
95 | support.setSupportName("minimized"); |
96 | support.setSupportType(Constants.WINDOW_STATE_SUPPORT); |
97 | supports.add(support); |
98 | |
99 | List portletApplications = new ArrayList(); |
100 | PortletApplication application = new PortletApplication(); |
101 | application.setContextPath("/my-dev"); |
102 | |
103 | List portletConfigs = new ArrayList(); |
104 | PortletConfig config = new PortletConfig(); |
105 | config.setPortletApplication(application); |
106 | config.setPortletName("AdminPortlet"); |
107 | portletConfigs.add(config); |
108 | |
109 | config = new PortletConfig(); |
110 | config.setPortletApplication(application); |
111 | config.setPortletName("PublishingPortlet"); |
112 | portletConfigs.add(config); |
113 | |
114 | config = new PortletConfig(); |
115 | config.setPortletApplication(application); |
116 | config.setPortletName("GroupsPortlet"); |
117 | portletConfigs.add(config); |
118 | |
119 | config = new PortletConfig(); |
120 | config.setPortletApplication(application); |
121 | config.setPortletName("ExamplePortlet"); |
122 | portletConfigs.add(config); |
123 | |
124 | application.setPortletConfigs(portletConfigs); |
125 | portletApplications.add(application); |
126 | |
127 | application = new PortletApplication(); |
128 | application.setContextPath("/onestartportlets"); |
129 | |
130 | portletConfigs = new ArrayList(); |
131 | config = new PortletConfig(); |
132 | config.setPortletApplication(application); |
133 | config.setPortletName("IframePortlet"); |
134 | portletConfigs.add(config); |
135 | |
136 | config = new PortletConfig(); |
137 | config.setPortletApplication(application); |
138 | config.setPortletName("RSSPortlet"); |
139 | portletConfigs.add(config); |
140 | |
141 | application.setPortletConfigs(portletConfigs); |
142 | portletApplications.add(application); |
143 | |
144 | application = new PortletApplication(); |
145 | application.setContextPath("/ccf-dev"); |
146 | |
147 | portletConfigs = new ArrayList(); |
148 | config = new PortletConfig(); |
149 | config.setPortletApplication(application); |
150 | config.setPortletName("ClassifiedsPortlet"); |
151 | portletConfigs.add(config); |
152 | |
153 | application.setPortletConfigs(portletConfigs); |
154 | portletApplications.add(application); |
155 | |
156 | application = new PortletApplication(); |
157 | application.setContextPath("/SpringPortlets"); |
158 | |
159 | portletConfigs = new ArrayList(); |
160 | config = new PortletConfig(); |
161 | config.setPortletApplication(application); |
162 | config.setPortletName("books"); |
163 | portletConfigs.add(config); |
164 | |
165 | portletConfigs = new ArrayList(); |
166 | config = new PortletConfig(); |
167 | config.setPortletApplication(application); |
168 | config.setPortletName("exceptions"); |
169 | portletConfigs.add(config); |
170 | |
171 | portletConfigs = new ArrayList(); |
172 | config = new PortletConfig(); |
173 | config.setPortletApplication(application); |
174 | config.setPortletName("mode"); |
175 | portletConfigs.add(config); |
176 | |
177 | portletConfigs = new ArrayList(); |
178 | config = new PortletConfig(); |
179 | config.setPortletApplication(application); |
180 | config.setPortletName("redirect"); |
181 | portletConfigs.add(config); |
182 | |
183 | portletConfigs = new ArrayList(); |
184 | config = new PortletConfig(); |
185 | config.setPortletApplication(application); |
186 | config.setPortletName("upload"); |
187 | portletConfigs.add(config); |
188 | |
189 | portletConfigs = new ArrayList(); |
190 | config = new PortletConfig(); |
191 | config.setPortletApplication(application); |
192 | config.setPortletName("helloworld"); |
193 | portletConfigs.add(config); |
194 | |
195 | application.setPortletConfigs(portletConfigs); |
196 | portletApplications.add(application); |
197 | |
198 | getAdminService().savePortalConfig(portalConfig); |
199 | } |
200 | this.portalConfig = portalConfig; |
201 | } |
202 | |
203 | private User getUser() { |
204 | String userName = "jdoe"; |
205 | String firstName = "John"; |
206 | String lastName = "Doe"; |
207 | String emailAddress = "jdoe@university.edu"; |
208 | String campusCode = "BL"; |
209 | List groups = new ArrayList(); |
210 | groups.add("group1"); |
211 | groups.add("group2"); |
212 | groups.add("group3"); |
213 | |
214 | OneStartUser oneStartUser = getUserService().findOneStartUserByUserName(userName); |
215 | return new User(oneStartUser, lastName, firstName, emailAddress, campusCode, groups); |
216 | } |
217 | |
218 | public void testPortalConfigValidatorValidate() { |
219 | try { |
220 | PortalConfig portalConfig = new PortalConfig(); |
221 | Errors errors = new BindException(portalConfig, "portalConfig"); |
222 | getPortalConfigValidator().validate(portalConfig, errors); |
223 | assertTrue("There should be errors from the validation. Required fields portal name, portal version, and container name.", errors.hasErrors()); |
224 | |
225 | } catch (Exception e) { |
226 | assertTrue("An error occured. " + e.toString(), false); |
227 | } |
228 | } |
229 | |
230 | public void testPortalConfigOnSubmitAction() { |
231 | try { |
232 | portalConfig.setPortalName("change"); |
233 | getPortalConfigController().onSubmitAction(portalConfig); |
234 | assertEquals("Portal config should have been updated.", "change", getAdminService().getPortalConfig().getPortalName()); |
235 | } catch (Exception e) { |
236 | assertTrue("An error occured. " + e.toString(), false); |
237 | } |
238 | } |
239 | |
240 | public void testPortalConfigOnSubmitRender() { |
241 | try { |
242 | ModelAndView modelAndView = getPortalConfigController().onSubmitRender(portalConfig); |
243 | |
244 | assertNotNull("ModelAndView does not contain content.", modelAndView.getModel()); |
245 | assertTrue("ModelAndView does not contain a confirmation message.", modelAndView.getModel().containsKey("message")); |
246 | } catch (Exception e) { |
247 | assertTrue("An error occured. " + e.toString(), false); |
248 | } |
249 | } |
250 | |
251 | public void testPortalConfigFormBackingObject() { |
252 | MockPortletRequest portletRequest = new MockPortletRequest(); |
253 | |
254 | try { |
255 | Object object = getPortalConfigController().formBackingObject(portletRequest); |
256 | assertTrue("Command object should be of type PortalConfig.", object instanceof PortalConfig); |
257 | |
258 | PortalConfig portalConfig = (PortalConfig) object; |
259 | assertNotNull("PortalConfig should be present.", portalConfig); |
260 | } catch (Exception e) { |
261 | assertTrue("An error occured. " + e.toString(), false); |
262 | } |
263 | } |
264 | |
265 | public void testPortalConfigViewHandleRenderRequestInternal() { |
266 | MockRenderRequest renderRequest = new MockRenderRequest(); |
267 | MockRenderResponse renderResponse = new MockRenderResponse(); |
268 | try { |
269 | ModelAndView modelAndView = getPortalConfigViewController().handleRenderRequestInternal(renderRequest, renderResponse); |
270 | |
271 | assertNotNull("ModelAndView does not contain content.", modelAndView.getModel()); |
272 | if (modelAndView.getModel() != null) { |
273 | assertTrue("ModelAndView does not contain a portal config.", modelAndView.getModel().containsKey("portalConfig")); |
274 | } |
275 | } catch (Exception e) { |
276 | assertTrue("An error occured. " + e.toString(), false); |
277 | } |
278 | } |
279 | |
280 | public OneStartUser getOneStartUser() { |
281 | return oneStartUser; |
282 | } |
283 | |
284 | public UserService getUserService() { |
285 | return userService; |
286 | } |
287 | |
288 | public void setUserService(UserService userService) { |
289 | this.userService = userService; |
290 | } |
291 | |
292 | public AdminService getAdminService() { |
293 | return adminService; |
294 | } |
295 | |
296 | public void setAdminService(AdminService adminService) { |
297 | this.adminService = adminService; |
298 | } |
299 | |
300 | public PortalConfigController getPortalConfigController() { |
301 | return portalConfigController; |
302 | } |
303 | |
304 | public void setPortalConfigController(PortalConfigController portalConfigController) { |
305 | this.portalConfigController = portalConfigController; |
306 | } |
307 | |
308 | public PortalConfigValidator getPortalConfigValidator() { |
309 | return portalConfigValidator; |
310 | } |
311 | |
312 | public void setPortalConfigValidator(PortalConfigValidator portalConfigValidator) { |
313 | this.portalConfigValidator = portalConfigValidator; |
314 | } |
315 | |
316 | public PortalConfigViewController getPortalConfigViewController() { |
317 | return portalConfigViewController; |
318 | } |
319 | |
320 | public void setPortalConfigViewController(PortalConfigViewController portalConfigViewController) { |
321 | this.portalConfigViewController = portalConfigViewController; |
322 | } |
323 | |
324 | } |