diff options
author | Madheswaran, Saravanan <msaravanan@in.ibm.com> | 2018-03-20 10:44:19 -0400 |
---|---|---|
committer | Madheswaran, Saravanan <msaravanan@in.ibm.com> | 2018-03-20 10:44:19 -0400 |
commit | 50125440c5371ae710674fec2b8d8f817aa1b4e4 (patch) | |
tree | 38c856bc7f5464238a078774bae17b4303bdb149 /ecomp-sdk/epsdk-analytics/src/test | |
parent | a932df953215fa4fe25d0dee962291eaa64d1846 (diff) |
Added Junits
Issue-ID: PORTAL-136
Includes JUNITS, Analytics module
Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed
Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed
Signed-off-by: Madheswaran, Saravanan <msaravanan@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test')
-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"); } |