diff options
author | Kotta, Shireesha (sk434m) <sk434m@att.com> | 2018-03-16 15:23:36 -0400 |
---|---|---|
committer | Kotta, Shireesha (sk434m) <sk434m@att.com> | 2018-03-16 16:00:12 -0400 |
commit | 826eea3037d2251539a7be3dafe829bc7d371e76 (patch) | |
tree | 9d327357b4b6e569373c15e50290e7d35e12741b /ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system | |
parent | 1e827d0b631a11fad2f5dcdf4e5feb8ad1eb214e (diff) |
Added Junits
Issue-ID: PORTAL-136
Includes JUNITS, Analytics module
Change-Id: Ib3053782fad98b6d6b2048bac1b9506c5cd8f42f
Signed-off-by: Kotta, Shireesha (sk434m) <sk434m@att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system')
2 files changed, 1160 insertions, 213 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/AppUtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/AppUtilsTest.java new file mode 100644 index 00000000..ed6103a7 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/AppUtilsTest.java @@ -0,0 +1,746 @@ +/* + * ============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.system; + +import static org.junit.Assert.*; + +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.owasp.esapi.ESAPI; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, ESAPI.class, Codec.class, SecurityCodecUtil.class }) +public class AppUtilsTest { + + @InjectMocks + AppUtils appUtils; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @SuppressWarnings("static-access") + @Test + public void generateFileNameTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserID(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.generateFileName(mockedRequest, "test"), "cr_test12test"); + } + + @SuppressWarnings("static-access") + @Test + public void generateUniqueFileNameTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserID(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.generateUniqueFileName(mockedRequest, "test", "test").getClass(), String.class); + } + + @SuppressWarnings("static-access") + @Test + public void getRequestValueTest() { + Mockito.when(mockedRequest.getAttribute(Matchers.anyString())).thenReturn(null); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + assertEquals(appUtils.getRequestValue(mockedRequest, "test"), "select *"); + } + + @SuppressWarnings("static-access") + @Test + public void getRequestNvlValueTest() { + Mockito.when(mockedRequest.getAttribute(Matchers.anyString())).thenReturn(null); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + assertEquals(appUtils.getRequestNvlValue(mockedRequest, "test"), "select *"); + } + + @SuppressWarnings("static-access") + @Test + public void getRequestFlagTest() { + Mockito.when(mockedRequest.getAttribute(Matchers.anyString())).thenReturn(null); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("yes"); + assertTrue(appUtils.getRequestFlag(mockedRequest, "test")); + } + + @SuppressWarnings("static-access") + @Test + public void getRequestFlag1Test() { + Mockito.when(mockedRequest.getAttribute(Matchers.anyString())).thenReturn(null); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("true"); + assertTrue(appUtils.getRequestFlag(mockedRequest, "test")); + } + + @SuppressWarnings("static-access") + @Test + public void getRequestFlag2Test() { + Mockito.when(mockedRequest.getAttribute(Matchers.anyString())).thenReturn(null); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + assertFalse(appUtils.getRequestFlag(mockedRequest, "test")); + } + + @SuppressWarnings("static-access") + @Test + public void getUserIDTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserID(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.getUserID(mockedRequest), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserNameest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserName(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.getUserName(mockedRequest), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserName1Test() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserName("test12")).thenReturn("test12"); + assertEquals(appUtils.getUserName("test12"), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserEmailTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserEmail("test12")).thenReturn("test12@test.com"); + assertEquals(appUtils.getUserEmail("test12"), "test12@test.com"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserEmail1est() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserEmail(mockedRequest)).thenReturn("test12@test.com"); + assertEquals(appUtils.getUserEmail(mockedRequest), "test12@test.com"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserLoginIdTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserLoginId(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.getUserLoginId(mockedRequest), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserLoginId1Test() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserLoginId("test12")).thenReturn("test12"); + assertEquals(appUtils.getUserLoginId("test12"), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUserBackdoorLoginIdTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test12"); + assertEquals(appUtils.getUserBackdoorLoginId(mockedRequest), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getAllUsersTest() { + Vector vc = new Vector<>(); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getAllUsers("test", "test", false)).thenReturn(vc); + appUtils.getAllUsers("test", "test", false); + } + + @SuppressWarnings("static-access") + @Test + public void getRoleNameTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getRoleName("test12")).thenReturn("test12"); + assertEquals(appUtils.getRoleName("test12"), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getAllRolesTest() { + Vector vc = new Vector<>(); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getAllRoles("test", "test", false)).thenReturn(vc); + appUtils.getAllRoles("test", "test", false); + } + + @SuppressWarnings("static-access") + @Test + public void isUserInRoleTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "1")).thenReturn(false); + assertFalse(appUtils.isUserInRole(mockedRequest, "1")); + } + + @SuppressWarnings("static-access") + @Test + public void getUserRolesTest() throws Exception { + Vector vc = new Vector<>(); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUserRoles("test")).thenReturn(vc); + appUtils.getUserRoles("test"); + } + + @SuppressWarnings("static-access") + @Test + public void resetUserCacheTest() throws Exception { + Vector vc = new Vector<>(); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.doNothing().when(iAppUtils).resetUserCache(); + appUtils.resetUserCache(); + } + + @SuppressWarnings("static-access") + @Test + public void getSuperRoleIDTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSuperRoleID()).thenReturn("test"); + assertEquals(appUtils.getSuperRoleID(), "test"); + } + + @SuppressWarnings("static-access") + @Test + public void getAdminRoleIDsTest() throws Exception { + Vector vc = new Vector<>(); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getAdminRoleIDs()).thenReturn(vc); + appUtils.getAdminRoleIDs(); + } + + @SuppressWarnings("static-access") + @Test + public void isSuperUserTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.isAdminRoleEquivalenttoSuperRole()).thenReturn(false); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSuperRoleID()).thenReturn("test"); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "1")).thenReturn(false); + assertFalse(appUtils.isSuperUser(mockedRequest)); + } + + @SuppressWarnings("static-access") + @Test + public void isAdminUserTst() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.isAdminRoleEquivalenttoSuperRole()).thenReturn(false); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSuperRoleID()).thenReturn("test"); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "1")).thenReturn(true); + + Vector vc = new Vector<>(); + Mockito.when(iAppUtils.getAdminRoleIDs()).thenReturn(vc); + + assertFalse(appUtils.isAdminUser(mockedRequest)); + } + + @SuppressWarnings("static-access") + @Test + public void isAdminUser1Tst() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.isAdminRoleEquivalenttoSuperRole()).thenReturn(false); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSuperRoleID()).thenReturn("test"); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "1")).thenReturn(true); + + Vector vc = new Vector<>(); + vc.add("test"); + Mockito.when(iAppUtils.getAdminRoleIDs()).thenReturn(vc); + Mockito.when(iAppUtils.isUserInRole(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(true); + + assertTrue(appUtils.isAdminUser(mockedRequest)); + } + + @SuppressWarnings("static-access") + @Test + public void isAdminUser2Tst() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.isAdminRoleEquivalenttoSuperRole()).thenReturn(false); + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSuperRoleID()).thenReturn("test"); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "1")).thenReturn(true); + + Vector vc = new Vector<>(); + vc.add("test"); + Mockito.when(iAppUtils.getAdminRoleIDs()).thenReturn(vc); + Mockito.when(iAppUtils.isUserInRole(mockedRequest, "test")).thenReturn(false); + + assertFalse(appUtils.isAdminUser(mockedRequest)); + } + + @SuppressWarnings("static-access") + @Test + public void getTempFolderPathTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn("test12"); + appUtils.getTempFolderPath(); + } + + @SuppressWarnings("static-access") + @Test + public void getTempFolderPath1Test() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn("test12\\"); + appUtils.getTempFolderPath(); + } + + @SuppressWarnings("static-access") + @Test + public void getTempFolderPath2Test() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn("test12/"); + appUtils.getTempFolderPath(); + } + + @SuppressWarnings("static-access") + @Test + public void getUploadFolderPathTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUploadFolderPath()).thenReturn("test12"); + appUtils.getUploadFolderPath(); + } + + @SuppressWarnings("static-access") + @Test + public void getUploadFolderPath1Test() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUploadFolderPath()).thenReturn("test12\\"); + appUtils.getUploadFolderPath(); + } + + @SuppressWarnings("static-access") + @Test + public void getTempFolderURLTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getTempFolderURL()).thenReturn("test12"); + assertEquals(appUtils.getTempFolderURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getUploadFolderURLTest() { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getUploadFolderURL()).thenReturn("test12"); + assertEquals(appUtils.getUploadFolderURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getSMTPServerTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getSMTPServer()).thenReturn("test12"); + assertEquals(appUtils.getSMTPServer(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getDefaultEmailSenderTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getDefaultEmailSender()).thenReturn("test12"); + assertEquals(appUtils.getDefaultEmailSender(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getErrorPageTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getErrorPage()).thenReturn("test12"); + + Mockito.when(iAppUtils.getJspContextPath()).thenReturn("test12"); + assertEquals(appUtils.getErrorPage(), "test12test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getJspContextPathTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getJspContextPath()).thenReturn("test12"); + assertEquals(appUtils.getJspContextPath(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getImgFolderURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getImgFolderURL()).thenReturn("test12"); + assertEquals(appUtils.getImgFolderURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getBaseFolderURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseFolderURL()).thenReturn("test12"); + assertEquals(appUtils.getBaseFolderURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getChartScriptsPathTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseFolderURL()).thenReturn("test12"); + Mockito.when(iAppUtils.getFolderPathAdj()).thenReturn("test12"); + assertEquals(appUtils.getChartScriptsPath(), "test12test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getChartScriptsPath1Test() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseFolderURL()).thenReturn("test12"); + assertEquals(appUtils.getChartScriptsPath("test"), "testtest12"); + } + + @SuppressWarnings("static-access") + @Test + public void getFolderPathAdjTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getFolderPathAdj()).thenReturn("test12"); + assertEquals(appUtils.getFolderPathAdj(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getDirectAccessURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getDirectAccessURL()).thenReturn("test12"); + assertEquals(appUtils.getDirectAccessURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getBaseURLLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURL()).thenReturn("test12"); + assertEquals(appUtils.getBaseURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getBaseURLL1Test() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURL()).thenReturn("test12?"); + assertEquals(appUtils.getBaseURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getBaseActionURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURL()).thenReturn("test12"); + assertEquals(appUtils.getBaseActionURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getDrillActionURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getDrillActionURL()).thenReturn("test12"); + assertEquals(appUtils.getDrillActionURL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getRaptorActionURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURL()).thenReturn("test12"); + assertEquals(appUtils.getRaptorActionURL(), "test12raptor&r_action="); + } + + @SuppressWarnings("static-access") + @Test + public void getRaptorActionURLNGTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURLNG()).thenReturn("test12"); + assertEquals(appUtils.getRaptorActionURLNG(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getReportExecuteActionURLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURLNG()).thenReturn("test12"); + assertEquals(appUtils.getReportExecuteActionURL(), "nullraptor&r_action=report.run.container&c_master="); + } + + @SuppressWarnings("static-access") + @Test + public void getReportExecuteActionURLNGTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionURLNG()).thenReturn("test12"); + assertEquals(appUtils.getReportExecuteActionURLNG(), "test12report_run/"); + } + + @SuppressWarnings("static-access") + @Test + public void getBaseActionParamTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getBaseActionParam()).thenReturn("test12"); + assertEquals(appUtils.getBaseActionParam(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getQuickLinksMenuIDsTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Vector vc = new Vector<>(); + Mockito.when(iAppUtils.getQuickLinksMenuIDs()).thenReturn(vc); + appUtils.getQuickLinksMenuIDs(); + } + + @SuppressWarnings("static-access") + @Test + public void getMenuLabelTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getMenuLabel("test")).thenReturn("test12"); + assertEquals(appUtils.getMenuLabel("test"), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getReportDbColsMaskSQLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getReportDbColsMaskSQL()).thenReturn("test12"); + assertEquals(appUtils.getReportDbColsMaskSQL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void getReportDbLookupsSQLTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getReportDbLookupsSQL()).thenReturn("test12"); + assertEquals(appUtils.getReportDbLookupsSQL(), "test12"); + } + + @SuppressWarnings("static-access") + @Test + public void processErrorNotificationTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.doNothing().when(iAppUtils).processErrorNotification(Matchers.any(HttpServletRequest.class), + Matchers.any(RaptorException.class)); + appUtils.processErrorNotification(mockedRequest, new RaptorException("test")); + } + + @SuppressWarnings("static-access") + @Test + public void getExcelTemplatePathTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getExcelTemplatePath()).thenReturn("test12"); + appUtils.getExcelTemplatePath(); + } + + @SuppressWarnings("static-access") + @Test + public void getExcelTemplatePath1Test() throws Exception { + PowerMockito.mockStatic(Globals.class); + IAppUtils iAppUtils = PowerMockito.mock(IAppUtils.class); + Mockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); + Mockito.when(iAppUtils.getExcelTemplatePath()).thenReturn("test12\\"); + appUtils.getExcelTemplatePath(); + } + + @SuppressWarnings("static-access") + @Test + public void nvlTest() { + assertEquals(appUtils.nvl(null), ""); + assertEquals(appUtils.nvl("test"), "test"); + assertEquals(appUtils.isNotEmpty(""), false); + assertEquals(appUtils.isNotEmpty("test"), true); + assertEquals(appUtils.nvls("test", "test1"), "test"); + assertEquals(appUtils.nvls(null, "test1"), "test1"); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java index 664e27c7..10e1d9e1 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java @@ -36,10 +36,14 @@ * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.portalsdk.analytics.system; -import static org.junit.Assert.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.sql.CallableStatement; import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; @@ -55,298 +59,495 @@ 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.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.core.web.support.AppUtils; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({AppUtils.class, Globals.class}) +@PrepareForTest({ AppUtils.class, Globals.class, Runtime.class, ConnectionUtils.class }) public class DbUtilsTest { @Mock DataSource dataSource; - + @InjectMocks DbUtils dbUtils = new DbUtils(); - + @Mock Connection connection; @Mock CallableStatement stmt; - + @Mock Statement statement; - + + @Mock + ResultSet rs; + @Before public void setup() { MockitoAnnotations.initMocks(this); } - + @SuppressWarnings("static-access") @Test - public void getConnectionTest() throws Exception - { + public void getConnectionTest() throws Exception { PowerMockito.mockStatic(AppUtils.class); Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); Mockito.when(dataSource.getConnection()).thenReturn(connection); dbUtils.getConnection(); } - + @SuppressWarnings({ "static-access", "unchecked" }) @Test - public void getConnectionExceptionTest() throws Exception - { + public void getConnectionExceptionTest() throws Exception { PowerMockito.mockStatic(AppUtils.class); Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class); Mockito.when(dataSource.getConnection()).thenReturn(connection); assertNull(dbUtils.getConnection()); } + + @SuppressWarnings("static-access") + @Test + public void clearConnectionTest() throws Exception + { + PowerMockito.mockStatic(Globals.class); + IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); + Mockito.when(Globals.getDbUtils()).thenReturn(iDbUtils); + Mockito.doNothing().when(iDbUtils).clearConnection(connection); + Globals.getDbUtils().clearConnection(connection); + Mockito.when(connection.isClosed()).thenReturn(false); + dbUtils.clearConnection(connection); + } - @SuppressWarnings("static-access") - @Test - public void clearConnectionTest() throws Exception - { - PowerMockito.mockStatic(Globals.class); - IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); - Mockito.when(Globals.getDbUtils()).thenReturn(iDbUtils); - Mockito.doNothing().when(iDbUtils).clearConnection(connection); - Globals.getDbUtils().clearConnection(connection); - Mockito.when(connection.isClosed()).thenReturn(false); - dbUtils.clearConnection(connection); - } + @SuppressWarnings("static-access") + @Test + public void clearConnection1Test() throws Exception + { + dbUtils.clearConnection(null); + } - @SuppressWarnings("static-access") - @Test - public void clearConnection1Test() throws Exception - { - dbUtils.clearConnection(null); - } + @SuppressWarnings({ "static-access", "unchecked" }) + @Test(expected = Exception.class) + public void clearConnectionExceptionTest() throws Exception + { + PowerMockito.mockStatic(Globals.class); + IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); + Mockito.when(Globals.getDbUtils()).thenThrow(Exception.class); + Mockito.doNothing().when(iDbUtils).clearConnection(connection); + Globals.getDbUtils().clearConnection(connection); + Mockito.when(connection.isClosed()).thenReturn(false); + dbUtils.clearConnection(connection); + } - @SuppressWarnings({ "static-access", "unchecked" }) - @Test(expected = Exception.class) - public void clearConnectionExceptionTest() throws Exception - { - PowerMockito.mockStatic(Globals.class); - IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); - Mockito.when(Globals.getDbUtils()).thenThrow(Exception.class); - Mockito.doNothing().when(iDbUtils).clearConnection(connection); - Globals.getDbUtils().clearConnection(connection); - Mockito.when(connection.isClosed()).thenReturn(false); - dbUtils.clearConnection(connection); - } + @SuppressWarnings({ "static-access", "unchecked" }) + @Test(expected = SQLException.class) + public void clearConnectionException2Test() throws Exception + { + PowerMockito.mockStatic(Globals.class); + IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); + Mockito.when(Globals.getDbUtils()).thenThrow(SQLException.class); + Mockito.doNothing().when(iDbUtils).clearConnection(connection); + Globals.getDbUtils().clearConnection(connection); + Mockito.when(connection.isClosed()).thenReturn(false); + dbUtils.clearConnection(connection); + } + @SuppressWarnings("static-access") + @Test + public void startTransactionTest() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.doNothing().when(connection).setAutoCommit(false); + dbUtils.startTransaction(); + } - @SuppressWarnings({ "static-access", "unchecked" }) - @Test(expected = SQLException.class) - public void clearConnectionException2Test() throws Exception - { - PowerMockito.mockStatic(Globals.class); - IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class); - Mockito.when(Globals.getDbUtils()).thenThrow(SQLException.class); - Mockito.doNothing().when(iDbUtils).clearConnection(connection); - Globals.getDbUtils().clearConnection(connection); - Mockito.when(connection.isClosed()).thenReturn(false); - dbUtils.clearConnection(connection); - } - @SuppressWarnings("static-access") - @Test - public void startTransactionTest() throws Exception - { - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); - Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.doNothing().when(connection).setAutoCommit(false); - dbUtils.startTransaction(); - } + @SuppressWarnings("static-access") + @Test(expected = ReportSQLException.class) + public void startTransactionExceptionTest() throws Exception + { + Mockito.doNothing().when(connection).setAutoCommit(false); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class); + Mockito.when(dataSource.getConnection()).thenReturn(null); + assertNull(dbUtils.startTransaction()); + } - @SuppressWarnings("static-access") - @Test(expected = ReportSQLException.class) - public void startTransactionExceptionTest() throws Exception - { - Mockito.doNothing().when(connection).setAutoCommit(false); - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class); - Mockito.when(dataSource.getConnection()).thenReturn(null); - assertNull(dbUtils.startTransaction()); - } + @SuppressWarnings({ "static-access", "unchecked" }) + @Test(expected = ReportSQLException.class) + public void startTransactionException1Test() throws Exception + { + Mockito.doNothing().when(connection).setAutoCommit(false); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenThrow(Exception.class); + Mockito.when(dataSource.getConnection()).thenReturn(null); + assertNull(dbUtils.startTransaction()); + } - @SuppressWarnings({ "static-access", "unchecked" }) - @Test(expected = ReportSQLException.class) - public void startTransactionException1Test() throws Exception - { - Mockito.doNothing().when(connection).setAutoCommit(false); - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenThrow(Exception.class); - Mockito.when(dataSource.getConnection()).thenReturn(null); - assertNull(dbUtils.startTransaction()); - } + @SuppressWarnings("static-access") + @Test + public void commitTransactionTest() throws Exception + { + Mockito.doNothing().when(connection).commit(); + dbUtils.commitTransaction(connection); + } - @SuppressWarnings("static-access") - @Test - public void commitTransactionTest() throws Exception - { - Mockito.doNothing().when(connection).commit(); - dbUtils.commitTransaction(connection); - } + @SuppressWarnings("static-access") + @Test(expected = RaptorException.class) + public void commitTransactionExceptionTest() throws Exception { + Mockito.doThrow(SQLException.class).when(connection).commit(); + dbUtils.commitTransaction(connection); + } - @SuppressWarnings("static-access") - @Test(expected = RaptorException.class) - public void commitTransactionExceptionTest() throws Exception { - Mockito.doThrow(SQLException.class).when(connection).commit(); - dbUtils.commitTransaction(connection); - } - - @SuppressWarnings("static-access") - @Test(expected = Exception.class) - public void commitTransactionException2Test() throws Exception { - Mockito.doThrow(Exception.class).when(connection).commit(); - dbUtils.commitTransaction(connection); - } + @SuppressWarnings("static-access") + @Test(expected = Exception.class) + public void commitTransactionException2Test() throws Exception { + Mockito.doThrow(Exception.class).when(connection).commit(); + dbUtils.commitTransaction(connection); + } -// @SuppressWarnings("static-access") -// @Test -// public void rollbackTransactionTest() throws Exception -// { -// Mockito.doNothing().when(connection).rollback(); -// dbUtils.rollbackTransaction(connection); -// } + // @SuppressWarnings("static-access") + // @Test + // public void rollbackTransactionTest() throws Exception + // { + // Mockito.doNothing().when(connection).rollback(); + // dbUtils.rollbackTransaction(connection); + // } - @SuppressWarnings("static-access") - @Test(expected = RaptorException.class) - public void rollbackTransactionExceptionTest() throws Exception { - Mockito.doThrow(SQLException.class).when(connection).rollback(); - dbUtils.rollbackTransaction(connection); - } - - @SuppressWarnings("static-access") - @Test(expected = Exception.class) - public void rollbackTransactionException2Test() throws Exception { - Mockito.doThrow(Exception.class).when(connection).rollback(); - dbUtils.rollbackTransaction(connection); - } + @SuppressWarnings("static-access") + @Test(expected = RaptorException.class) + public void rollbackTransactionExceptionTest() throws Exception { + Mockito.doThrow(SQLException.class).when(connection).rollback(); + dbUtils.rollbackTransaction(connection); + } - @SuppressWarnings("static-access") - @Test - public void executeCallTest() throws Exception - { - Mockito.when(connection.isClosed()).thenReturn(true); - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); - Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); - Mockito.when(stmt.getString(1)).thenReturn("test"); - dbUtils.executeCall(connection ,"test", false); - } + @SuppressWarnings("static-access") + @Test(expected = Exception.class) + public void rollbackTransactionException2Test() throws Exception { + Mockito.doThrow(Exception.class).when(connection).rollback(); + dbUtils.rollbackTransaction(connection); + } - @SuppressWarnings("static-access") - @Test - public void executeCall1Test() throws Exception - { - Mockito.when(connection.isClosed()).thenReturn(true); - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); - Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); - Mockito.when(stmt.getString(1)).thenReturn("test"); - dbUtils.executeCall(connection ,"test", true); - } + @SuppressWarnings("static-access") + @Test + public void executeCallTest() throws Exception + { + Mockito.when(connection.isClosed()).thenReturn(true); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(stmt.getString(1)).thenReturn("test"); + dbUtils.executeCall(connection ,"test", false); + } + + @SuppressWarnings("static-access") + @Test + public void executeCall1Test() throws Exception + { + Mockito.when(connection.isClosed()).thenReturn(true); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(stmt.getString(1)).thenReturn("test"); + dbUtils.executeCall(connection ,"test", true); + } + + + @SuppressWarnings({ "static-access", "unchecked" }) + @Test(expected = RaptorException.class) + public void executeCall2Test() throws Exception + { + Mockito.when(connection.isClosed()).thenReturn(true); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenThrow(SQLException.class); + Mockito.when(stmt.getString(1)).thenReturn("test"); + dbUtils.executeCall(connection ,"test", true); + } + + @SuppressWarnings("static-access") + @Test + public void executeCall3Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(stmt.getString(1)).thenReturn("test"); + dbUtils.executeCall("test", true); + } + @SuppressWarnings("static-access") + @Test + public void executeUpdateTest() throws Exception + { + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); + assertEquals(dbUtils.executeUpdate(connection, "test"),1); + } + + @SuppressWarnings({ "static-access", "unchecked" }) + @Test(expected = RaptorException.class ) + public void executeUpdate1Test() throws Exception + { + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeUpdate(Matchers.anyString())).thenThrow(SQLException.class); + dbUtils.executeUpdate(connection, "test"); + } + @SuppressWarnings("static-access") + @Test + public void executeUpdate2Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); + Mockito.when(stmt.getString(1)).thenReturn("test"); + Mockito.when(Globals.getDBType()).thenReturn("oracle"); + Mockito.doNothing().when(connection).commit(); + dbUtils.executeUpdate("test"); + } + @SuppressWarnings("static-access") + @Test + public void executeUpdate3Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); + Mockito.when(stmt.getString(1)).thenReturn("test"); + Mockito.when(Globals.getDBType()).thenReturn("oracle1"); + Mockito.doNothing().when(connection).commit(); + dbUtils.executeUpdate("test"); + } + + + @SuppressWarnings("static-access") + @Test(expected = RaptorException.class) + public void executeUpdate4Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); + Mockito.when(stmt.getString(1)).thenReturn("test"); + Mockito.when(Globals.getDBType()).thenReturn("oracle"); + Mockito.doThrow(SQLException.class).when(connection).commit(); + dbUtils.executeUpdate("test"); + } - @SuppressWarnings({ "static-access", "unchecked" }) - @Test(expected = RaptorException.class) - public void executeCall2Test() throws Exception - { - Mockito.when(connection.isClosed()).thenReturn(true); - PowerMockito.mockStatic(AppUtils.class); - Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); - Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenThrow(SQLException.class); - Mockito.when(stmt.getString(1)).thenReturn("test"); - dbUtils.executeCall(connection ,"test", true); - } + @SuppressWarnings("static-access") + @Test + public void executeQueryTest() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + dbUtils.executeQuery(connection, "test"); + } + + @SuppressWarnings("static-access") + @Test(expected = ReportSQLException.class) + public void executeQuery1Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(true); + Mockito.when(connection.createStatement()).thenThrow(SQLException.class); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + dbUtils.executeQuery(connection, "test"); + } + + @SuppressWarnings("static-access") + @Test(expected = ReportSQLException.class) + public void executeQuery2Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(false); + Mockito.when(connection.createStatement()).thenThrow(SQLException.class); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + dbUtils.executeQuery(connection, "test"); + } + + @SuppressWarnings("static-access") + @Test(expected = ReportSQLException.class) + public void executeQuery3Test() throws Exception + { + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); + Mockito.when(dataSource.getConnection()).thenReturn(connection); + Mockito.when(connection.isClosed()).thenReturn(false); + Mockito.when(connection.createStatement()).thenThrow(SQLException.class); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + dbUtils.executeQuery(connection, "test", 1); + } + + @SuppressWarnings("static-access") @Test - public void executeCall3Test() throws Exception - { + public void executeQuery4Test() throws Exception { PowerMockito.mockStatic(AppUtils.class); Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); Mockito.when(dataSource.getConnection()).thenReturn(connection); Mockito.when(connection.isClosed()).thenReturn(true); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); - Mockito.when(stmt.getString(1)).thenReturn("test"); - dbUtils.executeCall("test", true); - } - @SuppressWarnings("static-access") - @Test - public void executeUpdateTest() throws Exception - { Mockito.when(connection.createStatement()).thenReturn(statement); - Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); - assertEquals(dbUtils.executeUpdate(connection, "test"),1); - } - - @SuppressWarnings({ "static-access", "unchecked" }) - @Test(expected = RaptorException.class ) - public void executeUpdate1Test() throws Exception - { - Mockito.when(connection.createStatement()).thenReturn(statement); - Mockito.when(statement.executeUpdate(Matchers.anyString())).thenThrow(SQLException.class); - dbUtils.executeUpdate(connection, "test"); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + dbUtils.executeQuery("test", 1); } + @SuppressWarnings("static-access") @Test - public void executeUpdate2Test() throws Exception - { + public void executeQuery5Test() throws Exception { PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); Mockito.when(dataSource.getConnection()).thenReturn(connection); Mockito.when(connection.isClosed()).thenReturn(true); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); Mockito.when(connection.createStatement()).thenReturn(statement); - Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); - Mockito.when(stmt.getString(1)).thenReturn("test"); - Mockito.when(Globals.getDBType()).thenReturn("oracle"); - Mockito.doNothing().when(connection).commit(); - dbUtils.executeUpdate("test"); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + Mockito.when(rr.getDBInfo()).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(rr.getWholeSQL()).thenReturn("test"); + DataColumnType dc = PowerMockito.mock(DataColumnType.class); + Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc); + Mockito.when(dc.getColId()).thenReturn("test"); + Mockito.when(dc.getColFormat()).thenReturn("test"); + dbUtils.executeQuery(rr, 1); } - + @SuppressWarnings("static-access") @Test - public void executeUpdate3Test() throws Exception - { + public void executeQuery6Test() throws Exception { PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); Mockito.when(dataSource.getConnection()).thenReturn(connection); Mockito.when(connection.isClosed()).thenReturn(true); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); Mockito.when(connection.createStatement()).thenReturn(statement); - Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); - Mockito.when(stmt.getString(1)).thenReturn("test"); - Mockito.when(Globals.getDBType()).thenReturn("oracle1"); - Mockito.doNothing().when(connection).commit(); - dbUtils.executeUpdate("test"); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + Mockito.when(rr.getDBInfo()).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(rr.getWholeSQL()).thenReturn("test"); + DataColumnType dc = PowerMockito.mock(DataColumnType.class); + Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc); + Mockito.when(dc.getColId()).thenReturn("test"); + Mockito.when(dc.getColFormat()).thenReturn("test"); + dbUtils.executeQuery(rr, 2); } - - + @SuppressWarnings("static-access") - @Test(expected = RaptorException.class) - public void executeUpdate4Test() throws Exception - { + @Test + public void executeQuery7Test() throws Exception { PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource); Mockito.when(dataSource.getConnection()).thenReturn(connection); Mockito.when(connection.isClosed()).thenReturn(true); - Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt); Mockito.when(connection.createStatement()).thenReturn(statement); - Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1); - Mockito.when(stmt.getString(1)).thenReturn("test"); - Mockito.when(Globals.getDBType()).thenReturn("oracle"); - Mockito.doThrow(SQLException.class).when(connection).commit(); - dbUtils.executeUpdate("test"); + Mockito.when(statement.executeQuery("test")).thenReturn(rs); + PowerMockito.mockStatic(Runtime.class); + Mockito.when(Runtime.getRuntime()).thenReturn(null); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + Mockito.when(rs.getMetaData()).thenReturn(rsmd); + Mockito.when(rsmd.getColumnCount()).thenReturn(1); + Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test"); + Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + Mockito.when(rr.getDBInfo()).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(rr.getWholeSQL()).thenReturn("test"); + DataColumnType dc = PowerMockito.mock(DataColumnType.class); + Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc); + Mockito.when(dc.getColId()).thenReturn("test"); + Mockito.when(dc.getColFormat()).thenReturn("test"); + dbUtils.executeQuery(rr, 3); + } + + @Test + public void nvlTest() { + assertEquals(dbUtils.nvl(null), ""); + assertEquals(dbUtils.nvl("test"), "test"); + assertEquals(dbUtils.nvls("test"), "test"); + assertEquals(dbUtils.nvls(null), ""); + assertEquals(dbUtils.nvl("test", "test1"), "test"); + assertEquals(dbUtils.nvl(null, "test1"), "test1"); } - } |