From 50125440c5371ae710674fec2b8d8f817aa1b4e4 Mon Sep 17 00:00:00 2001 From: "Madheswaran, Saravanan" Date: Tue, 20 Mar 2018 10:44:19 -0400 Subject: Added Junits Issue-ID: PORTAL-136 Includes JUNITS, Analytics module Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed Signed-off-by: Madheswaran, Saravanan --- .../analytics/model/ReportHandlerTest.java | 112 ++++++++++++++++++--- 1 file 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; @@ -129,6 +126,9 @@ public class ReportHandlerTest { @Mock FileOutputStream fileOutputStream; + @Mock + PrintWriter printWriter; + @Mock DataSourceList dataSourceList; @@ -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 paramList = null; + paramList = new ArrayList(); + 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 paramList = null; + paramList = new ArrayList(); + 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); + } + /* @@ -506,11 +599,6 @@ public class ReportHandlerTest { } - @Test - public void testCreateCSVFileContent() { - fail("Not yet implemented"); - } - @Test public void testSaveXMLFile() { fail("Not yet implemented"); -- cgit 1.2.3-korg