diff options
author | 2018-03-21 10:36:54 -0400 | |
---|---|---|
committer | 2018-03-21 11:31:34 -0400 | |
commit | 458097945996fd40d822c6938c1aedd349bfcfeb (patch) | |
tree | b64cd8276ea6dbab899c0d633bd8ba833705d99b /ecomp-sdk/epsdk-analytics | |
parent | 0c82c3e2b86be4605a874113eef49b2d8a0bd2e9 (diff) |
Added Junits
Issue-ID: PORTAL-136
Includes JUNITS, Analytics module
Change-Id: Ie4234c6d940d72866e11b56619840cdc707e4005
Change-Id: I8ed32ab32c8455fccf9baa1ce66441aea08f4d75
Signed-off-by: Madheswaran, Saravanan <msaravanan@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics')
3 files changed, 526 insertions, 47 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardProcessorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardProcessorTest.java index 837c2c32..7af40812 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardProcessorTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardProcessorTest.java @@ -73,6 +73,7 @@ import org.onap.portalsdk.analytics.xmlobj.ColFilterType; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.analytics.xmlobj.DataSourceType; import org.onap.portalsdk.analytics.xmlobj.FormFieldType; +import org.onap.portalsdk.analytics.xmlobj.FormatType; import org.onap.portalsdk.analytics.xmlobj.JavascriptItemType; import org.onap.portalsdk.analytics.xmlobj.ReportMap; import org.onap.portalsdk.analytics.xmlobj.SemaphoreList; @@ -141,6 +142,9 @@ public class WizardProcessorTest { @Mock Encoder encoder; + @Mock + FormatType formatingType; + private String REPORT_ID="1000"; private String DETAIL_ID="3000"; @@ -3058,25 +3062,24 @@ public class WizardProcessorTest { } - /*** - @Test + @Test(expected=Exception.class) public void testProcessSemaphorePopup_case1() throws Exception { mockHttpAttribute("semaphoreId", "Id"); mockHttpAttribute("semaphoreName", "Name"); mockHttpAttribute("semaphoreType", "Type"); - String [] formatId = {"", ""}; - String [] lessThanValue = {"1", "1"}; - String [] expression = {"", ""}; - String [] bold = {"", ""}; - String [] italic = {"", ""}; - String [] underline = {"", ""}; - String [] bgColor = {"", ""}; - String [] fontColor = {"", ""}; - String [] fontFace = {"", ""}; - String [] fontSize = {"", ""}; + String [] formatId = {"1"}; + String [] lessThanValue = {"1"}; + String [] expression = {""}; + String [] bold = {""}; + String [] italic = {""}; + String [] underline = {""}; + String [] bgColor = {""}; + String [] fontColor = {""}; + String [] fontFace = {""}; + String [] fontSize = {""}; mockHttpParameterValues("formatId", formatId); mockHttpParameterValues("lessThanValue", lessThanValue); @@ -3091,27 +3094,31 @@ public class WizardProcessorTest { SemaphoreType semaphoreType = new SemaphoreType(); - //Mockito.when(reportDefinition.getSemaphoreFormatById(Mockito.anyObject(), Mockito.anyString())).thenReturn(new FormatType()); - //PowerMockito.when(reportDefinition.addEmptyFormatType(Mockito.anyObject(), Mockito.anyObject())).thenReturn(new FormatType()); - - Mockito.when(reportDefinition.addSemaphoreType( Mockito.anyObject(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new SemaphoreType()); - - Mockito.when(reportDefinition.getSemaphoreById("Id")).thenReturn(semaphoreType); - - PowerMockito.when(ReportDefinition.getSemaphoreFormatById( Mockito.anyObject(), Mockito.anyString())).thenReturn(new FormatType()); - - //Mockito.when(reportDefinition.getSemaphoreById("Id")).thenReturn(null); + semaphoreType.setSemaphoreName("TEST SEMAPHORE"); - //Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList); + Mockito.when(reportDefinition.getSemaphoreById("Id")).thenReturn(semaphoreType); + Mockito.when(reportDefinition.addSemaphoreType( Mockito.anyObject(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(semaphoreType); + + /* + FormatType formatType = new FormatType(); + formatType.setBgColor("blue"); + formatType.setFontColor("black"); + formatType.setBold(true); + formatType.setItalic(true); + formatType.setFontFace("Calibri"); + formatType.setItalic(true); + formatType.setUnderline(true); + formatType.setUnderline(true); + formatType.setFontSize("20"); + */ + Mockito.when(reportDefinition.getSemaphoreById("Id")).thenReturn(semaphoreType); - //Mockito.when(reportDefinition.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1); + //Mockito.when(reportDefinition.getSemaphoreFormatById(Mockito.anyObject(), Mockito.anyString())).thenReturn(formatingType); wizardProcessor.processSemaphorePopup(httpServletRequest); - Mockito.verify(wizardProcessor, Mockito.times(1)).processSemaphorePopup(httpServletRequest); + //Mockito.verify(wizardProcessor, Mockito.times(1)).processSemaphorePopup(httpServletRequest); } - ***/ - /* diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java index 3a5a4477..4322c3b8 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java @@ -1,5 +1,5 @@ /* - * ============LICENSE_START========================================== + * ============LICENxSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -39,19 +39,17 @@ package org.onap.portalsdk.analytics.gmap.node; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; - +import java.awt.Point; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; - import org.junit.Test; import org.onap.portalsdk.analytics.gmap.map.NovaMap; import org.onap.portalsdk.analytics.gmap.node.Node; - public class NodeTest { - + @Test public void testNode_null_argument() { Node nodeObj = new Node(null); @@ -78,6 +76,8 @@ public class NodeTest { } + + @Test public void testUpdateNumberCase1() { @@ -107,9 +107,12 @@ public class NodeTest { @Test public void testUpdateNumberCase2() { + Node nodeObj = new Node(new NovaMap()); + + nodeObj.updateNumberT1("year"); - + HashMap<String,NodeInfo> hashMap = nodeObj.getNodeCollection().getNodeCollection(); assertNotNull(hashMap); @@ -119,8 +122,11 @@ public class NodeTest { for (Iterator iterator = set.iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); NodeInfo nodeInfo = (NodeInfo) entry.getValue(); + assertEquals("2018", nodeInfo.getAttribute(NodeInfo.NUMBER_OF_T1_KEY)); + } + } @Test @@ -130,8 +136,7 @@ public class NodeTest { nodeObj.getUniqueNumberT1(""); } - - /** + /* @Test public void testGetUniqueNumberTcase2() { @@ -148,26 +153,59 @@ public class NodeTest { } - } -***/ - - + } + */ + @Test public void testNodeExist() { Node nodeObj = new Node(new NovaMap()); - //nodeObj.nodeExist(); + + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + + Point pointObj= new Point(3,3); + nodeObj.nodeExist(pointObj); + // assertNotNull(existNodeInfo); + + // assertEquals("2018", existNodeInfo.get(1); + } + @Test public void testGetNodeCollection() { + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + + nodeObj.getNodeCollection(); + assertNotNull(nodeObj.getNodeCollection()); } @Test public void testClearNodeIDSet() { + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + nodeObj.clearNodeIDSet(); } @Test public void testClearSelectionList() { + + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + nodeObj.clearSelectionList(); + + } + + @Test + public void testClearSelectionList_EmptyNode() { + Node nodeObj = new Node(new NovaMap()); + nodeObj.clearSelectionList(); + } } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java index f44739d1..35f7700c 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java @@ -44,9 +44,17 @@ package org.onap.portalsdk.analytics.model; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import javax.servlet.ServletContext; import javax.servlet.ServletOutputStream; @@ -61,10 +69,12 @@ import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.onap.portalsdk.analytics.controller.WizardSequence; +import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.system.IAppUtils; @@ -74,15 +84,23 @@ import org.onap.portalsdk.analytics.view.DataValue; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; import org.onap.portalsdk.analytics.view.ReportRowHeaderCols; +import org.onap.portalsdk.analytics.xmlobj.DataColumnList; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.analytics.xmlobj.DataSourceList; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreList; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; import org.owasp.esapi.ESAPI; import org.owasp.esapi.Encoder; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; + @RunWith(PowerMockRunner.class) -@PrepareForTest({Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class}) +@PrepareForTest({Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class, ConnectionUtils.class}) public class ReportHandlerTest { private ReportHandler reportHandler; @@ -144,6 +162,18 @@ public class ReportHandlerTest { @Mock File file; + @Mock + Connection connection; + + @Mock + Statement statement; + + @Mock + ResultSet resultSet; + + @Mock + ResultSetMetaData resultSetMetaData; + private String REPORT_ID = "1000"; @Before @@ -154,6 +184,7 @@ public class ReportHandlerTest { PowerMockito.mockStatic(IAppUtils.class); PowerMockito.mockStatic(ESAPI.class); PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ConnectionUtils.class); PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file); Mockito.when(file.createNewFile()).thenReturn(true); @@ -246,6 +277,140 @@ public class ReportHandlerTest { Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); } + + + + + + @Test + public void testSaveAsExcelFile_case2() throws Exception { + String saveOutput = ""; + ReportData reportData = prepareReportData(); + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> listDataSourceType = dataSourceList.getDataSource(); + + DataSourceType dataSourceType1 = new DataSourceType(); + + DataColumnList dataColumnList1 = new DataColumnList(); + List<DataColumnType> listDataColumnType1 = dataColumnList1.getDataColumn(); + + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setSemaphoreId("Id1"); + listDataColumnType1.add(dataColumnType1); + + dataSourceType1.setDataColumnList(dataColumnList1); + + listDataSourceType.add(dataSourceType1); + + + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); + + ArrayList <IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + String para = ""; + + int i=1; + while(i<20) { + para = para + "<p>This is a paragraph.</p>" + "\n" + "<p>This is another paragraph.</p>" + "\n"; + i++; + } + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn(para); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + //ReflectionTestUtils.setField(reportData, "reportRowHeaderCols", reportRowHeaderCols); + + + SemaphoreList semaphoreList = new SemaphoreList(); + List<SemaphoreType> listSemaphoreType = semaphoreList.getSemaphore(); + + SemaphoreType st1 = new SemaphoreType(); + SemaphoreType st2 = new SemaphoreType(); + FormatList formatList = new FormatList(); + + List<FormatType> listFormatType = formatList.getFormat(); + + FormatType formatType1 = new FormatType(); + FormatType formatType2 = new FormatType(); + + listFormatType.add(formatType1); + + formatType2.setBgColor("blue"); + formatType2.setFontColor("black"); + formatType2.setBold(true); + formatType2.setItalic(true); + formatType2.setFontFace("Calibri"); + formatType2.setItalic(true); + formatType2.setUnderline(true); + formatType2.setUnderline(true); + formatType2.setFontSize("20"); + + listFormatType.add(formatType2); + + + st1.setSemaphoreName("Name1"); + st1.setSemaphoreId("Id1"); + + st1.setFormatList(formatList); + + st2.setSemaphoreName("Name2"); + st2.setSemaphoreId("Id2"); + + st2.setFormatList(formatList); + listSemaphoreType.add(st1); + listSemaphoreType.add(st2); + + mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID); + + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList); + Mockito.when(reportDefinition.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1); + + + + saveOutput = reportHandler.saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + //Assert.assertNotNull(saveOutput); + Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + } + + + + + + + + + + + + + + + + + + private ArrayList<DataRow> prepareDataRowList(){ ArrayList <DataRow> alDataRow = new ArrayList<DataRow>(); @@ -327,7 +492,6 @@ public class ReportHandlerTest { DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); @@ -422,8 +586,8 @@ public class ReportHandlerTest { } - - + + @Test public void testCreateExcel2007FileContent_case1() throws Exception { @@ -477,11 +641,96 @@ public class ReportHandlerTest { */ reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); - } + + + @Test - public void testCreateCSVFileContent_case1() throws Exception { + public void testCreateExcel2007FileContent_case2() throws Exception { + + + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList <IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); + + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn(REPORT_ID); + + + Map<String, ReportRuntime> mapReportRuntime = new TreeMap<String, ReportRuntime>(); + Map<String, ReportData> mapReportData = new TreeMap<String, ReportData>(); + + mapReportRuntime.put("ReportRuntime#1", reportRuntime); + mapReportData.put("ReportData#1", reportData); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(mapReportRuntime); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(mapReportData); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); + Mockito.when(reportRuntime.getTemplateFile()).thenReturn(""); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + + /* + PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); + */ + reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); + + + } + + + + + + + + + + + + + + @Test + public void testCreateCSVFileContent_WithoutSql_case1() throws Exception { ReportData reportData = prepareReportData(); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); @@ -525,13 +774,66 @@ public class ReportHandlerTest { reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); } + @Test + public void testCreateCSVFileContent_WithSql_case1() throws Exception { + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); + Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); + + + ArrayList <IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); + } + private void mockHttpAttribute(String attributeName, String attributeValue) { Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue); } @Test - public void testCreateHTMLFileContent() throws Exception { + public void testCreateHTMLFileContent_WithoutSql_case1() throws Exception { ReportData reportData = prepareReportData(); @@ -577,7 +879,139 @@ public class ReportHandlerTest { reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "", httpServletRequest, httpServletResponse); } + + @Test(expected =RaptorException.class) + public void testCreateHTMLFileContent_WithSql_case1() throws Exception { + + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); + Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); + + ArrayList <IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + + //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + + Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "select column1 from table1 where column2='test'", httpServletRequest, httpServletResponse); + } + + + @Test + public void testCreateFlatFileContent_case1() throws IOException, Exception { + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + + ArrayList <IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); + + Mockito.when(reportRuntime.loadReportData(Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(reportData); + + Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + DataColumnType dataColumnType1 = new DataColumnType(); + + dataColumnType1.setTableId("reportaccess"); + dataColumnType1.setDbColName("REP_ID"); + dataColumnType1.setColName("REP_ID"); + dataColumnType1.setDbColType("INTEGER"); + dataColumnType1.setDisplayName("Report Id"); + + DataColumnType dataColumnType2 = new DataColumnType(); + + dataColumnType2.setTableId("reportaccess"); + dataColumnType2.setDbColName("ORDER_NO"); + dataColumnType2.setColName("ORDER_NO"); + dataColumnType2.setDbColType("INTEGER"); + dataColumnType2.setDisplayName("Order No"); + + List<DataColumnType> listDataColumnType = new ArrayList<DataColumnType>(); + listDataColumnType.add(dataColumnType1); + listDataColumnType.add(dataColumnType2); + + Mockito.when(reportRuntime.getAllColumns()).thenReturn(listDataColumnType); + + + reportHandler.createFlatFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "USER#1"); + + } + /* |