diff options
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java | 112 |
1 files changed, 100 insertions, 12 deletions
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 8cb83e6a..f44739d1 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 @@ -40,12 +40,11 @@ package org.onap.portalsdk.analytics.model; -import org.apache.commons.io.FilenameUtils; -import org.junit.Assert; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.PrintWriter; import java.io.Writer; import java.util.ArrayList; @@ -61,8 +60,6 @@ import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.onap.portalsdk.analytics.controller.WizardSequence; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; @@ -130,6 +127,9 @@ public class ReportHandlerTest { FileOutputStream fileOutputStream; @Mock + PrintWriter printWriter; + + @Mock DataSourceList dataSourceList; @Mock @@ -479,12 +479,105 @@ public class ReportHandlerTest { } - + + @Test + public void testCreateCSVFileContent_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, null); + + + 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); + + 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.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 { - - + 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, null); + + + 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); + + 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, "", httpServletRequest, httpServletResponse); + } + /* @@ -507,11 +600,6 @@ public class ReportHandlerTest { @Test - public void testCreateCSVFileContent() { - fail("Not yet implemented"); - } - - @Test public void testSaveXMLFile() { fail("Not yet implemented"); } |