diff options
author | 2018-06-08 16:40:16 -0400 | |
---|---|---|
committer | 2018-06-14 10:03:31 -0400 | |
commit | f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 (patch) | |
tree | db4f24c3bc4e70bcda2916d7fa7027e9ab984cf3 /ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util | |
parent | 1ffd6b689a0176875b401fb089bd33db96f07b62 (diff) |
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) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java new file mode 100644 index 00000000..63a72c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java @@ -0,0 +1,192 @@ +/* + * ============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.util; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.IdNameValue; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class, Utils.class}) +public class UtilsTest { + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpSession session = mockedRequest.getSession(); + + @Test + public void getUsersNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInList(list, mockedRequest); + } + + @Test + public void getRolesNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInList(list, mockedRequest); + } + + @Test + public void getUsersNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInListLatest(list, mockedRequest); + } + + @Test + public void getRolesNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInListLatest(list, mockedRequest); + } + + @Test + public void isDownloadFileExistsTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.isDownloadFileExists("test"); + } + + @Test + public void getLatestDownloadableFileTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt","test1.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.getLatestDownloadableFile("test"); + } + + @Test + public void javaSafeTest() throws Exception { + Utils.javaSafe("Hel'oo world!"); + } + + @Test(expected=RuntimeException.class) + public void _assertTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getDebugLevel()).thenReturn(1); + Utils._assert(false, "errorMsg"); + } + + @Test + public void getCurrentDateTimeTest() { + Utils.getCurrentDateTime(); + } + + @Test + public void htmlEncodeTest() { + Utils.htmlEncode("<html>test</html>"); + } + + +} |