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.model.pdf;
40 import static org.mockito.Mockito.mock;
41 import static org.mockito.Mockito.when;
44 import java.util.ArrayList;
45 import java.util.TreeMap;
47 import javax.servlet.ServletContext;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.mockito.InjectMocks;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
57 import org.onap.portalsdk.analytics.system.AppUtils;
58 import org.onap.portalsdk.analytics.system.DbUtils;
59 import org.onap.portalsdk.analytics.system.Globals;
60 import org.onap.portalsdk.analytics.util.AppConstants;
61 import org.onap.portalsdk.analytics.view.ReportData;
62 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PrepareForTest;
65 import org.powermock.modules.junit4.PowerMockRunner;
67 import com.lowagie.text.Document;
69 @RunWith(PowerMockRunner.class)
70 @PrepareForTest({ PdfReportHandler.class, AppUtils.class, Globals.class, DbUtils.class})
71 public class PdfReportHandlerTest {
74 PdfReportHandler pdfReportHandler;
77 public void init() throws Exception {
78 PowerMockito.mockStatic(Globals.class);
79 PowerMockito.mockStatic(AppUtils.class);
80 PowerMockito.mockStatic(DbUtils.class);
81 MockitoAnnotations.initMocks(this);
84 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
85 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
86 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
88 @SuppressWarnings({ "rawtypes", "unchecked" })
90 public void createPdfFileContentTest() throws Exception {
91 Document doc = mock(Document.class);
92 PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc);
93 PowerMockito.when(doc.newPage()).thenReturn(true);
94 when(AppUtils.getUserID(mockedRequest)).thenReturn("test");
95 ReportRuntime rr = mock(ReportRuntime.class);
96 ReportData rd = mock(ReportData.class);
97 when(Globals.isCoverPageNeeded()).thenReturn(true);
98 when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1");
99 when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1");
100 when(rr.isPDFCoverPage()).thenReturn(true);
101 when(rr.getReportID()).thenReturn("test");
102 when(rr.getPDFOrientation()).thenReturn("portait");
103 when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr);
104 when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test");
105 ServletContext servConxt = mock(ServletContext.class);
106 when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt);
107 when(servConxt.getRealPath(File.separator)).thenReturn("testpath");
108 when(rr.getChartType()).thenReturn("test");
109 when(rr.getDisplayChart()).thenReturn(true);
110 ArrayList paramNamePDFValues = new ArrayList();
111 paramNamePDFValues.add("test1");
112 paramNamePDFValues.add("test2");
113 when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues);
114 when(rr.getFormFieldComments(mockedRequest)).thenReturn("test");
115 TreeMap values = new TreeMap<>();
116 values.put("test", rr);
117 TreeMap values2 = new TreeMap<>();
118 values2.put("test3", rd);
119 TreeMap values3 = new TreeMap<>();
120 values3.put("test4", "c");
121 when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values);
122 when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2);
123 when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3);
124 pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3);