Added Junits 45/37145/1
authorMadheswaran, Saravanan <msaravanan@in.ibm.com>
Tue, 20 Mar 2018 14:44:19 +0000 (10:44 -0400)
committerMadheswaran, Saravanan <msaravanan@in.ibm.com>
Tue, 20 Mar 2018 14:44:19 +0000 (10:44 -0400)
Issue-ID: PORTAL-136

Includes JUNITS, Analytics module

Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed

Change-Id: Iad7b856f3f547040f3c399a829fa8c88254604ed
Signed-off-by: Madheswaran, Saravanan <msaravanan@in.ibm.com>
ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java

index 8cb83e6..f44739d 100644 (file)
 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 <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);
+       }
+
        
        /*
 
@@ -506,11 +599,6 @@ public class ReportHandlerTest {
        }
 
 
-       @Test
-       public void testCreateCSVFileContent() {
-               fail("Not yet implemented");
-       }
-
        @Test
        public void testSaveXMLFile() {
                fail("Not yet implemented");