2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 package org.onap.portalsdk.analytics.controller;
42 import static org.junit.Assert.*;
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpSession;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.mockito.Mock;
51 import org.mockito.Mockito;
52 import org.mockito.MockitoAnnotations;
53 import org.mockito.invocation.InvocationOnMock;
54 import org.mockito.stubbing.Answer;
55 import org.onap.portalsdk.analytics.model.ReportHandler;
56 import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
57 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
58 import org.onap.portalsdk.analytics.system.AppUtils;
59 import org.onap.portalsdk.analytics.system.DbUtils;
60 import org.onap.portalsdk.analytics.system.Globals;
61 import org.onap.portalsdk.analytics.system.IAppUtils;
62 import org.onap.portalsdk.analytics.util.AppConstants;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PrepareForTest;
65 import org.powermock.modules.junit4.PowerMockRunner;
67 @RunWith(PowerMockRunner.class)
68 @PrepareForTest({ WizardProcessor.class, AppUtils.class, Globals.class, DbUtils.class})
69 public class WizardProcessorTest {
71 WizardProcessor wizardProcessor;
74 HttpServletRequest httpServletRequest;
77 HttpSession httpSession;
83 ReportRuntime reportRuntime;
86 ReportHandler reportHandler;
89 ReportDefinition reportDefinition;
92 WizardSequence wizardSequence;
96 public void init() throws Exception {
98 PowerMockito.mockStatic(Globals.class);
99 PowerMockito.mockStatic(AppUtils.class);
100 PowerMockito.mockStatic(DbUtils.class);
102 MockitoAnnotations.initMocks(this);
104 PowerMockito.when(Globals.getAppUtils()).thenReturn(iAppUtils);
105 PowerMockito.when(AppUtils.getImgFolderURL()).thenReturn("http://sometesturl:9090/hi");
106 PowerMockito.when(httpServletRequest.getSession()).thenReturn(httpSession);
108 PowerMockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition);
110 PowerMockito.when(AppUtils.nvl(Mockito.anyString())).thenAnswer(new Answer<String>() {
112 public String answer(InvocationOnMock invocation) throws Throwable {
113 Object[] args = invocation.getArguments();
114 String inputString = (String) args[0];
115 return (inputString == null) ? "" : inputString;
119 PowerMockito.when(AppUtils.getRequestNvlValue(Mockito.anyObject(), Mockito.anyString())).thenAnswer(new Answer<String>() {
121 public String answer(InvocationOnMock invocation) throws Throwable {
122 Object[] args = invocation.getArguments();
123 HttpServletRequest request = (HttpServletRequest) args[0];
124 String valueID = (String) args[1];
125 String value = (String) request.getAttribute(valueID);
129 value = ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(), request.getParameter(valueID));
132 return (value == null) ? "" : value;
137 PowerMockito.when(AppUtils.getRequestValue(Mockito.anyObject(), Mockito.anyString())).thenAnswer(new Answer<String>() {
139 public String answer(InvocationOnMock invocation) throws Throwable {
140 Object[] args = invocation.getArguments();
141 HttpServletRequest request = (HttpServletRequest) args[0];
142 String valueID = (String) args[1];
143 String value = (String) request.getAttribute(valueID);
147 value = ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(), request.getParameter(valueID));
156 wizardProcessor = new WizardProcessor();
161 public void testWizardProcessor() {
162 WizardProcessor wizardProcessorLocal = new WizardProcessor();
164 assertNotNull(wizardProcessorLocal);
167 @Test(expected=NullPointerException.class)
168 public void testPersistReportDefinition_null_arguments() throws Exception {
169 wizardProcessor.persistReportDefinition(null, null);
172 @Test(expected=NullPointerException.class)
173 public void testPersistReportDefinition_null_arguments_case1() throws Exception {
174 wizardProcessor.persistReportDefinition(httpServletRequest, null);
177 @Test(expected=NullPointerException.class)
178 public void testPersistReportDefinition_null_arguments_case2() throws Exception {
179 Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
180 wizardProcessor.persistReportDefinition(httpServletRequest, null);
183 @Test(expected=NullPointerException.class)
184 public void testPersistReportDefinition_null_arguments_case3() throws Exception {
185 Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
186 PowerMockito.when(reportRuntime.getReportID()).thenReturn("Report#1");
188 wizardProcessor.persistReportDefinition(httpServletRequest, null);
192 public void testPersistReportDefinition_not_null_arguments_case1() throws Exception {
193 Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
194 Mockito.when(reportRuntime.getReportID()).thenReturn("Report#1");
195 wizardProcessor.persistReportDefinition(httpServletRequest, reportDefinition);
199 public void testPersistReportDefinition_not_null_arguments_case2() throws Exception {
200 Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
201 Mockito.when(reportRuntime.getReportID()).thenReturn("Report#1");
202 Mockito.when(reportDefinition.getReportID()).thenReturn("Report#1");
204 wizardProcessor.persistReportDefinition(httpServletRequest, reportDefinition);
207 @Test(expected=NullPointerException.class)
208 public void testProcessWizardStep_null_arguments_case1() throws Exception {
209 wizardProcessor.processWizardStep(null);
212 @Test(expected=NullPointerException.class)
213 public void testProcessWizardStep_not_null_arguments_case1() throws Exception {
214 wizardProcessor.processWizardStep(httpServletRequest);
217 @Test(expected=NullPointerException.class)
218 public void testProcessWizardStep_not_null_arguments_case2() throws Exception {
219 Mockito.when(httpServletRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn(null);
220 wizardProcessor.processWizardStep(httpServletRequest);
223 @Test(expected=NullPointerException.class)
224 public void testProcessWizardStep_not_null_arguments_case3() throws Exception {
225 Mockito.when(httpServletRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("NA");
226 wizardProcessor.processWizardStep(httpServletRequest);
230 public void testProcessWizardStep_not_null_arguments_case4() throws Exception {
231 PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler);
232 Mockito.when(AppUtils.getRequestValue(httpServletRequest, AppConstants.RI_REPORT_ID)).thenReturn("Report#1");
233 Mockito.when(reportHandler.loadReportDefinition(httpServletRequest,"Report#1")).thenReturn(reportDefinition);
234 Mockito.when(httpServletRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("NA");
235 Mockito.when(AppUtils.getRequestNvlValue(httpServletRequest, "showDashboardOptions")).thenReturn("");
236 Mockito.when(reportDefinition.getWizardSequence()).thenReturn(wizardSequence);
237 Mockito.when(wizardSequence.getCurrentStep()).thenReturn("NA");
238 Mockito.when(wizardSequence.getCurrentSubStep()).thenReturn("NA");
239 wizardProcessor.processWizardStep(httpServletRequest);
243 public void testProcessWizardStep_not_null_arguments_case5() throws Exception {
244 PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler);
245 Mockito.when(AppUtils.getRequestValue(httpServletRequest, AppConstants.RI_REPORT_ID)).thenReturn("Report#1");
246 Mockito.when(AppUtils.getRequestNvlValue(httpServletRequest, "showDashboardOptions")).thenReturn("");
248 Mockito.when(AppUtils.getRequestNvlValue(httpServletRequest, "reportType")).thenReturn(AppConstants.RT_DASHBOARD);
249 Mockito.when(reportHandler.loadReportDefinition(httpServletRequest,"Report#1")).thenReturn(reportDefinition);
251 Mockito.when(httpServletRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("NA");
252 Mockito.when(reportDefinition.getWizardSequence()).thenReturn(wizardSequence);
253 Mockito.when(wizardSequence.getCurrentStep()).thenReturn(AppConstants.WS_DEFINITION);
254 Mockito.when(wizardSequence.getCurrentSubStep()).thenReturn("NA");
256 Mockito.when(reportDefinition.getReportID()).thenReturn("1");
258 wizardProcessor.processWizardStep(httpServletRequest);
265 public void testProcessImportSemaphorePopup() {
266 fail("Not yet implemented");
270 public void testProcessSemaphorePopup() {
271 fail("Not yet implemented");
275 public void testProcessAdhocSchedule() {
276 fail("Not yet implemented");