From f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 Mon Sep 17 00:00:00 2001 From: "Kishore Reddy, Gujja (kg811t)" Date: Fri, 8 Jun 2018 16:40:16 -0400 Subject: Junit Test Cases & Raptors Issue-ID: PORTAL-273. PORTAL-301 Covered JUNITS for sdk modules and RAPTOR reports fixes Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525 Signed-off-by: Kishore Reddy, Gujja (kg811t) --- .../portalsdk/analytics/model/DataCacheTest.java | 328 +++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java') diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java new file mode 100644 index 00000000..a9b1bac2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java @@ -0,0 +1,328 @@ +/* + * ============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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model; + +import java.util.Vector; + +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.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.pdf.PdfReportHandler; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, DbUtils.class, AppUtils.class }) +public class DataCacheTest { + @InjectMocks + DataCache dataCache = new DataCache(); + + @Before + public void init() throws Exception { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + DataSet ds; + + @SuppressWarnings("static-access") + @Test + public void getDataViewActionsTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheDataViewActions()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(1, 0)).thenReturn("test"); + dataCache.getDataViewActions(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getGroupAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheGroupAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getTheGroupAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getGroupAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void getTableSourceTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest2() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest3() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest1() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest2() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + dataCache.getReportTableJoins(vc); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest3() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest4() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } +} -- cgit 1.2.3-korg