summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk
diff options
context:
space:
mode:
authorMadheswaran, Saravanan <msaravanan@in.ibm.com>2018-03-15 09:45:50 -0400
committerMadheswaran, Saravanan <msaravanan@in.ibm.com>2018-03-15 09:45:50 -0400
commit663322e6843cc60de18f13873726d50cdbbe8608 (patch)
tree072cfb54a7e8951671d4ca4d89c07f0306d1f552 /ecomp-sdk
parent59465af26eaec33902d9de7b3b57c7744eb02435 (diff)
Added Junits
Issue-ID: PORTAL-136 Includes JUNITS, Analytics module Change-Id: I951a26acebc1863eabc799cb57538593ca650e5a Change-Id: I951a26acebc1863eabc799cb57538593ca650e5a Signed-off-by: Madheswaran, Saravanan <msaravanan@in.ibm.com>
Diffstat (limited to 'ecomp-sdk')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardProcessorTest.java255
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportHandlerTest.java122
2 files changed, 207 insertions, 170 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 d287ab55..837c2c32 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
@@ -40,7 +40,6 @@ package org.onap.portalsdk.analytics.controller;
import static org.junit.Assert.*;
-import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
@@ -75,16 +74,18 @@ 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.JavascriptItemType;
-import org.onap.portalsdk.analytics.xmlobj.ObjectFactory;
+import org.onap.portalsdk.analytics.xmlobj.ReportMap;
import org.onap.portalsdk.analytics.xmlobj.SemaphoreList;
import org.onap.portalsdk.analytics.xmlobj.SemaphoreType;
import org.onap.portalsdk.core.domain.User;
+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({DbUtils.class, Globals.class, IAppUtils.class, WizardProcessor.class})//, RaptorAdapter.class})
+@PrepareForTest({DbUtils.class, Globals.class, IAppUtils.class, WizardProcessor.class, ESAPI.class})
public class WizardProcessorTest {
WizardProcessor wizardProcessor;
@@ -137,6 +138,9 @@ public class WizardProcessorTest {
@Mock
ReportSecurity reportSecurity;
+ @Mock
+ Encoder encoder;
+
private String REPORT_ID="1000";
private String DETAIL_ID="3000";
@@ -145,14 +149,17 @@ public class WizardProcessorTest {
PowerMockito.mockStatic(DbUtils.class);
PowerMockito.mockStatic(Globals.class);
- PowerMockito.mockStatic(IAppUtils.class);
+ PowerMockito.mockStatic(IAppUtils.class);
+ PowerMockito.mockStatic(ESAPI.class);
Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession);
Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition);
Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(reportSchedule);
Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
-
+
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+
PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler);
PowerMockito.when(Globals.getAppUtils()).thenReturn(appUtils);
@@ -173,6 +180,20 @@ public class WizardProcessorTest {
wizardProcessor = Mockito.spy(WizardProcessor.class);
}
+
+
+ private void mockHttpAttribute(String attributeName, String attributeValue) {
+ Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue);
+ }
+
+ private void mockHttpParameter(String parameterName, String parameterValue) {
+ Mockito.when(httpServletRequest.getParameter(parameterName)).thenReturn(parameterValue);
+ }
+
+ private void mockHttpParameterValues(String parameterName, String[] parameterValue) {
+ Mockito.when(httpServletRequest.getParameterValues(parameterName)).thenReturn(parameterValue);
+ }
+
@Test
public void testWizardProcessor() {
@@ -180,7 +201,6 @@ public class WizardProcessorTest {
assertNotNull(wizardProcessorLocal);
}
-
@Test(expected=NullPointerException.class)
public void testPersistReportDefinition_null_arguments() throws Exception {
@@ -952,8 +972,74 @@ public class WizardProcessorTest {
wizardProcessor.processWizardStep(httpServletRequest);
Mockito.verify(wizardProcessor, Mockito.times(1)).processWizardStep(httpServletRequest);
}
+
+ @Test
+ public void testProcessWizardStep_processForecasting_case1() throws Exception {
+ mockHttpParameter(AppConstants.RI_WIZARD_ACTION, AppConstants.RI_ACTION);
+ mockHttpAttribute(AppConstants.RI_REPORT_ID,REPORT_ID);
+ mockHttpAttribute("showDashboardOptions","");
+ mockHttpAttribute(AppConstants.RI_DETAIL_ID,DETAIL_ID);
+
+ mockHttpAttribute("timeAttribute", null);
+ mockHttpAttribute("timeFormat", "");
+ mockHttpAttribute("forecastingPeriod", "10hr");
+ mockHttpAttribute("classifiers", "Y");
+
+ mockHttpParameterValues("forecastCol", null);
+
+ setWizardSteps(AppConstants.WS_DATA_FORECASTING, AppConstants.WSS_INFO_BAR);
+ Mockito.when(encoder.encodeForSQL(Mockito.anyObject(), Mockito.anyString())).thenReturn(null);
+
+ wizardProcessor.processWizardStep(httpServletRequest);
+ Mockito.verify(wizardProcessor, Mockito.times(1)).processWizardStep(httpServletRequest);
+ }
+
+ @Test
+ public void testProcessWizardStep_processForecasting_case2() throws Exception {
+ mockHttpParameter(AppConstants.RI_WIZARD_ACTION, AppConstants.RI_ACTION);
+ mockHttpAttribute(AppConstants.RI_REPORT_ID,REPORT_ID);
+ mockHttpAttribute("showDashboardOptions","");
+ mockHttpAttribute(AppConstants.RI_DETAIL_ID,DETAIL_ID);
+
+ mockHttpAttribute("timeAttribute", "REP_ID");
+ mockHttpAttribute("timeFormat", "Default");
+ mockHttpAttribute("forecastingPeriod", "10hr");
+ mockHttpAttribute("classifiers", "Y");
+
+ String []forecastCol = {"REP_ID", "ORDER_NO"};
+ mockHttpParameterValues("forecastCol", forecastCol);
+
+ setWizardSteps(AppConstants.WS_DATA_FORECASTING, AppConstants.WSS_INFO_BAR);
+
+ DataColumnType dataColumnType1 = new DataColumnType();
+
+ dataColumnType1.setTableId("reportaccess");
+ dataColumnType1.setDbColName("REP_ID");
+ dataColumnType1.setColName("REP_ID");
+ dataColumnType1.setDbColType("INTEGER");
+ dataColumnType1.setDisplayName("Report Id");
+ dataColumnType1.setColId("REP_ID");
+
+ DataColumnType dataColumnType2 = new DataColumnType();
+
+ dataColumnType2.setTableId("reportaccess");
+ dataColumnType2.setDbColName("ORDER_NO");
+ dataColumnType2.setColName("ORDER_NO");
+ dataColumnType2.setDbColType("INTEGER");
+ dataColumnType2.setDisplayName("Order No");
+ dataColumnType2.setColId("ORDER_NO");
+
+ List<DataColumnType> listDataColumnType = new ArrayList<DataColumnType>();
+ listDataColumnType.add(dataColumnType1);
+ listDataColumnType.add(dataColumnType2);
+ Mockito.when(reportDefinition.getAllColumns()).thenReturn(listDataColumnType);
+
+ wizardProcessor.processWizardStep(httpServletRequest);
+ Mockito.verify(wizardProcessor, Mockito.times(1)).processWizardStep(httpServletRequest);
+ }
+
@Test
public void testProcessWizardStep_processFilterAddEdit_case1() throws Exception {
mockHttpParameter(AppConstants.RI_WIZARD_ACTION, "ACTION");
@@ -2942,6 +3028,7 @@ public class WizardProcessorTest {
Mockito.verify(wizardProcessor, Mockito.times(1)).processImportSemaphorePopup(httpServletRequest);
}
+
@Test
public void testProcessImportSemaphore_case2() throws Exception {
SemaphoreList semaphoreList = new SemaphoreList();
@@ -2970,37 +3057,61 @@ public class WizardProcessorTest {
Mockito.verify(wizardProcessor, Mockito.times(1)).processImportSemaphorePopup(httpServletRequest);
}
- /*
+ /***
+
@Test
public void testProcessSemaphorePopup_case1() throws Exception {
- SemaphoreList semaphoreList = new SemaphoreList();
- List<SemaphoreType> listSemaphoreType = semaphoreList.getSemaphore();
- SemaphoreType st1 = new SemaphoreType();
- SemaphoreType st2 = new SemaphoreType();
+ 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 = {"", ""};
- st1.setSemaphoreName("Name1");
- st1.setSemaphoreId("Id1");
-
- st2.setSemaphoreName("Name2");
- st2.setSemaphoreId("Id2");
-
- listSemaphoreType.add(st1);
- listSemaphoreType.add(st2);
+ mockHttpParameterValues("formatId", formatId);
+ mockHttpParameterValues("lessThanValue", lessThanValue);
+ mockHttpParameterValues("expression", expression);
+ mockHttpParameterValues("bold", bold);
+ mockHttpParameterValues("italic", italic);
+ mockHttpParameterValues("underline", underline);
+ mockHttpParameterValues("bgColor", bgColor);
+ mockHttpParameterValues("fontColor", fontColor);
+ mockHttpParameterValues("fontFace", fontFace);
+ mockHttpParameterValues("fontSize", fontSize);
- mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID);
+ SemaphoreType semaphoreType = new SemaphoreType();
- Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList);
+ //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.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1);
+ 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);
+
+ //Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList);
+
+ //Mockito.when(reportDefinition.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1);
+
wizardProcessor.processSemaphorePopup(httpServletRequest);
- Mockito.verify(wizardProcessor, Mockito.times(1)).processImportSemaphorePopup(httpServletRequest);
- }
+ Mockito.verify(wizardProcessor, Mockito.times(1)).processSemaphorePopup(httpServletRequest);
+ }
+ ***/
-*/
/*
@@ -3160,19 +3271,6 @@ public class WizardProcessorTest {
***/
- /***
-
- @throws Exception
- * @Test
- public void testProcessImportSemaphorePopup() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testProcessSemaphorePopup() {
- fail("Not yet implemented");
- }
-*/
@Test
public void testProcessAdhocSchedule_Add_User_case1() throws Exception {
@@ -3338,16 +3436,77 @@ public class WizardProcessorTest {
}
- private void mockHttpAttribute(String attributeName, String attributeValue) {
- Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue);
- }
-
- private void mockHttpParameter(String parameterName, String parameterValue) {
- Mockito.when(httpServletRequest.getParameter(parameterName)).thenReturn(parameterValue);
- }
+ @Test
+ public void testProcessWizardStep_processMap_case1() throws Exception {
+ mockHttpParameter(AppConstants.RI_WIZARD_ACTION, AppConstants.RI_ACTION);
+ mockHttpAttribute(AppConstants.RI_REPORT_ID,REPORT_ID);
+ mockHttpAttribute("showDashboardOptions","");
+ mockHttpAttribute(AppConstants.RI_DETAIL_ID,DETAIL_ID);
+
+ setWizardSteps(AppConstants.WS_MAP, AppConstants.WA_SAVE);
+
+ mockHttpAttribute("addressColumn0", "");
+ mockHttpAttribute("dataColumn0", "");
+ mockHttpAttribute("legendColumn", "");
+ mockHttpAttribute("markerColor0", "");
+ mockHttpAttribute("isMapAllowed", "");
+ mockHttpAttribute("useDefaultSize", "");
+ mockHttpAttribute("height", "");
+ mockHttpAttribute("width", "");
+ mockHttpAttribute("addAddress", "");
+ mockHttpAttribute("latColumn", "");
+ mockHttpAttribute("longColumn", "");
+ mockHttpAttribute("colorColumn", "");
+
+ mockHttpAttribute("markerCount", "");
+
+
+ Mockito.when(reportDefinition.getReportMap()).thenReturn(null);
+ wizardProcessor.processWizardStep(httpServletRequest);
+
+ Mockito.verify(wizardProcessor, Mockito.times(1)).processWizardStep(httpServletRequest);
+ }
- private void mockHttpParameterValues(String parameterName, String[] parameterValue) {
- Mockito.when(httpServletRequest.getParameterValues(parameterName)).thenReturn(parameterValue);
- }
+ @Test
+ public void testProcessWizardStep_processMap_case2() throws Exception {
+ mockHttpParameter(AppConstants.RI_WIZARD_ACTION, AppConstants.RI_ACTION);
+ mockHttpAttribute(AppConstants.RI_REPORT_ID,REPORT_ID);
+ mockHttpAttribute("showDashboardOptions","");
+ mockHttpAttribute(AppConstants.RI_DETAIL_ID,DETAIL_ID);
+
+ setWizardSteps(AppConstants.WS_MAP, AppConstants.WA_SAVE);
+
+ ReportMap reportMap = new ReportMap();
+
+ mockHttpAttribute("addressColumn0", "Y");
+ mockHttpAttribute("dataColumn0", "Y");
+ mockHttpAttribute("legendColumn", "Y");
+ mockHttpAttribute("markerColor0", "Y");
+ mockHttpAttribute("isMapAllowed", "Y");
+ mockHttpAttribute("useDefaultSize", "Y");
+ mockHttpAttribute("height", "Y");
+ mockHttpAttribute("width", "Y");
+ mockHttpAttribute("addAddress", "Y");
+ mockHttpAttribute("latColumn", "Y");
+ mockHttpAttribute("longColumn", "Y");
+ mockHttpAttribute("colorColumn", "Y");
+
+ mockHttpAttribute("markerCount", "3");
+
+ mockHttpAttribute("addressColumn1", "1");
+ mockHttpAttribute("dataHeader1", "Header1");
+ mockHttpAttribute("dataColumn1", "DataColumn1");
+ mockHttpAttribute("markerColor1", "Color1");
+
+ mockHttpAttribute("addressColumn2", "2");
+ mockHttpAttribute("dataHeader2", "Header2");
+ mockHttpAttribute("dataColumn2", "DataColumn2");
+ mockHttpAttribute("markerColor2", "Color2");
+
+ Mockito.when(reportDefinition.getReportMap()).thenReturn(reportMap);
+ wizardProcessor.processWizardStep(httpServletRequest);
+
+ Mockito.verify(wizardProcessor, Mockito.times(1)).processWizardStep(httpServletRequest);
+ }
}
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportHandlerTest.java
deleted file mode 100644
index bb31dbce..00000000
--- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportHandlerTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.portalsdk.analytics.xmlobj;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.portalsdk.analytics.error.ReportSQLException;
-import org.onap.portalsdk.analytics.model.ReportHandler;
-import org.onap.portalsdk.analytics.model.base.ReportWrapper;
-import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
-import org.onap.portalsdk.analytics.system.DbUtils;
-import org.onap.portalsdk.analytics.system.Globals;
-import org.onap.portalsdk.analytics.util.AppConstants;
-import org.onap.portalsdk.analytics.view.ReportData;
-import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
-import org.onap.portalsdk.analytics.xmlobj.DataSourceList;
-import org.onap.portalsdk.analytics.xmlobj.DataSourceType;
-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)
-public class ReportHandlerTest {
-
-
-// @InjectMocks
-// ReportHandler reportHandler = new ReportHandler();
-//
-// @Before
-// public void setup() {
-// MockitoAnnotations.initMocks(this);
-// }
-//
-// MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
-// HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
-// HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
-// NullPointerException nullPointerException = new NullPointerException();
-//
-
-// @Test
-// public void loadStylesTest() throws RaptorException, Exception
-// {
-// ReportData rd = new ReportData(1, true);
-// List reportParamNameValues = new ArrayList<>();
-// PowerMockito.mockStatic(Globals.class);
-//
-// PowerMockito.mockStatic(Globals.class);
-// PowerMockito.mockStatic(DbUtils.class);
-//
-// Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
-// ResultSet rs = PowerMockito.mock(ResultSet.class);
-// DataSet datset = PowerMockito.mock(DataSet.class);
-// // datset = new DataSet(rs);
-// Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
-// Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
-// Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
-// CustomReportType customReportType = new CustomReportType();
-// customReportType.setReportType("test");
-// ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1",
-// "1", true);
-// ReportRuntime reportRuntime = new ReportRuntime(reportWrapper);
-//
-//
-// DataSourceType type = new DataSourceType();
-// type.setDisplayName("test");
-// DataSourceList list = new DataSourceList();
-// reportRuntime.setDataSourceList(list);
-// Mockito.when(mockedRequest.getAttribute(
-// AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime);
-// reportHandler.saveAsExcelFile(mockedRequest, rd, (ArrayList) reportParamNameValues, "test", "test" , 1);
-// }
-
-}