summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java192
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>");
+ }
+
+
+}