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.
38 package org.onap.portalsdk.analytics.view;
40 import java.sql.ResultSet;
41 import java.sql.ResultSetMetaData;
42 import java.util.ArrayList;
43 import java.util.List;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.InjectMocks;
52 import org.mockito.Matchers;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.onap.portalsdk.analytics.controller.ActionHandler;
56 import org.onap.portalsdk.analytics.error.RaptorException;
57 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
58 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
59 import org.onap.portalsdk.analytics.system.AppUtils;
60 import org.onap.portalsdk.analytics.system.ConnectionUtils;
61 import org.onap.portalsdk.analytics.system.DbUtils;
62 import org.onap.portalsdk.analytics.system.Globals;
63 import org.onap.portalsdk.analytics.util.DataSet;
64 import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions;
65 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
66 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
67 import org.onap.portalsdk.analytics.xmlobj.DataSourceList;
68 import org.onap.portalsdk.analytics.xmlobj.DataSourceType;
69 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
70 import org.onap.portalsdk.core.web.support.UserUtils;
71 import org.powermock.api.mockito.PowerMockito;
72 import org.powermock.core.classloader.annotations.PrepareForTest;
73 import org.powermock.modules.junit4.PowerMockRunner;
75 @RunWith(PowerMockRunner.class)
76 @PrepareForTest({Globals.class,DbUtils.class, UserUtils.class, AppUtils.class} )
77 public class CrossTabOrderManagerTest {
80 ActionHandler actionHandler = new ActionHandler();
84 MockitoAnnotations.initMocks(this);
87 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
88 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
89 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
92 public void mockCrossTabOrderManagerTest() throws Exception
94 PowerMockito.mockStatic(Globals.class);
95 PowerMockito.mockStatic(DbUtils.class);
96 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
97 ResultSet rs = PowerMockito.mock(ResultSet.class);
98 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
99 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
100 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
101 DataSet datset = PowerMockito.mock(DataSet.class);
102 // datset = new DataSet(rs);
103 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
104 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
105 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
106 CustomReportType customReportType = new CustomReportType();
107 DataSourceList dataSourceList = new DataSourceList();
108 List<DataSourceType> list = new ArrayList<>();
109 DataSourceType dataSourceType = new DataSourceType();
110 dataSourceType.setTableName("test");
111 dataSourceType.setRefTableId("1");
112 dataSourceType.setTableId("1");
113 List<DataColumnType> dataColumnTypeList = new ArrayList<>();
114 DataColumnType dataColumnType = new DataColumnType();
115 dataColumnType.setChartGroup("test");
116 dataColumnType.setYAxis("test");
117 dataColumnType.setColName("[test");
118 dataColumnType.setColOnChart("LEGEND");
119 dataColumnType.setDisplayName("chart_total");
120 dataColumnType.setColId("1");
121 dataColumnType.setTableId("1");
122 dataColumnType.setColType("DATE");
123 dataColumnTypeList.add(dataColumnType);
124 customReportType.setReportType("test");
125 customReportType.setReportTitle("test");
126 customReportType.setDataSourceList(dataSourceList);
127 ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions();
128 chartAdditionalOptions.setLabelAngle("test");
129 chartAdditionalOptions.setTimeSeriesRender("test");
130 chartAdditionalOptions.setMultiSeries(false);
131 customReportType.setChartAdditionalOptions(chartAdditionalOptions);
132 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
134 PowerMockito.mockStatic(UserUtils.class);
135 Mockito.when(Globals.getRequestParams()).thenReturn("test");
136 Mockito.when(Globals.getSessionParams()).thenReturn("test");
137 Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test");
138 PowerMockito.mockStatic(AppUtils.class);
139 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
140 ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest);
141 CrossTabOrderManager crossTabOrderManager= new CrossTabOrderManager(rr,"test",mockedRequest);