2dce46c0ccdabc3d82a3df24db2f93951defe922
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalsdk.analytics.model.runtime;
39
40 import java.util.ArrayList;
41
42 import javax.servlet.http.HttpServletRequest;
43
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.Matchers;
48 import org.mockito.Mockito;
49 import org.onap.portalsdk.analytics.error.RaptorException;
50 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
51 import org.onap.portalsdk.analytics.system.AppUtils;
52 import org.onap.portalsdk.analytics.util.AppConstants;
53 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
54 import org.onap.portalsdk.core.web.support.UserUtils;
55 import org.powermock.api.mockito.PowerMockito;
56 import org.powermock.core.classloader.annotations.PrepareForTest;
57 import org.powermock.modules.junit4.PowerMockRunner;
58
59 @RunWith(PowerMockRunner.class)
60 @PrepareForTest({ UserUtils.class, AppUtils.class})
61 public class ChartWebRuntimeTest {
62         ChartWebRuntime chartWebRuntime;
63         
64         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
65         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
66         
67         @Before
68         public void init() {
69                 chartWebRuntime = new ChartWebRuntime();
70                 ArrayList chartList = new ArrayList<>();
71                 chartList.add("test");
72                 ArrayList infoList = new ArrayList<>();
73                 infoList.add("test");
74                 chartWebRuntime.setChartList(chartList);
75                 chartWebRuntime.setInfoList(infoList);
76                 chartWebRuntime.setTotalSql("select * from test");
77         }
78         
79         @Test
80         public void testBarChartOptionsProperties() throws RaptorException {
81                 PowerMockito.mockStatic(UserUtils.class);
82                 PowerMockito.mockStatic(AppUtils.class);
83                 Mockito.when(mockedRequest.getParameter("action")).thenReturn("test");
84                 Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(10);
85                 Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true);
86                 Mockito.when(AppUtils.nvl(Mockito.anyString())).thenReturn("test");
87                 Mockito.when(mockedRequest.getParameter("refresh")).thenReturn("N");
88                 Mockito.when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1");
89                 Mockito.when(AppUtils.getRequestNvlValue(Mockito.any(HttpServletRequest.class), Mockito.anyString())).thenReturn("test");
90                 ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
91                 Mockito.when(rr.getReportID()).thenReturn("1");
92                 Mockito.when(rr.getReportType()).thenReturn("Hive");
93                 Mockito.when(rr.getReportSQL()).thenReturn("select * from test");
94                 Mockito.when(rr.getLegendLabelAngle()).thenReturn("standard");
95                 Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr);
96                 ReportWrapper rw = PowerMockito.mock(ReportWrapper.class);
97                 ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest);
98                 FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
99                                 "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL",
100                                 "rangeEndDateSQL", "multiSelectListSize");
101                 FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
102                                 "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL",
103                                 "rangeEndDateSQL", "multiSelectListSize");
104                 FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false,
105                                 "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL",
106                                 "rangeEndDateSQL", "multiSelectListSize");
107
108                 reportFormFields.add(formField);
109                 reportFormFields.add(formField1);
110                 reportFormFields.add(formField2);
111                 Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields);
112                 Mockito.when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED);
113                 Mockito.when(rr.getReportTitle()).thenReturn("test");
114                 Mockito.when(mockedRequest.getParameterValues(Matchers.anyString())).thenReturn(new String[] { "test" });
115                 chartWebRuntime.generateChart(mockedRequest);
116         }
117 }