summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common/src/test/java')
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java103
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java145
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java52
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java24
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java8
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java5
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java19
7 files changed, 310 insertions, 46 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
index 59b5a8ed..4df1c2ac 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
@@ -1,5 +1,5 @@
/*-
- * ============LICENSE_START==========================================
+ * ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
@@ -90,7 +90,10 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
@RunWith(PowerMockRunner.class)
@PrepareForTest({SystemProperties.class,AppUtils.class, EPUserUtils.class, MediaType.class})
@@ -548,7 +551,7 @@ public class AppsControllerTest extends MockitoTestSuite{
List<AppsResponse> atualApps = new ArrayList<AppsResponse>();
Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
- Mockito.when(appService.getAllApps(false)).thenReturn(expectedApps);
+ Mockito.when(appService.getAllApplications(false)).thenReturn(expectedApps);
atualApps = appsController.getApps(mockedRequest, mockedResponse);
assertEquals(expectedApps, atualApps);
}
@@ -566,7 +569,7 @@ public class AppsControllerTest extends MockitoTestSuite{
EPUser user = mockUser.mockEPUser();
Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
- Mockito.when(appService.getAllApps(false)).thenThrow(nullPointerException);
+ Mockito.when(appService.getAllApplications(false)).thenThrow(nullPointerException);
assertNull(appsController.getApps(mockedRequest, mockedResponse));
}
@@ -725,24 +728,110 @@ public class AppsControllerTest extends MockitoTestSuite{
}
@Test
- public void putOnboardingAppTest() {
+ public void putOnboardingAppTest() throws Exception {
EPUser user = mockUser.mockEPUser();
Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
OnboardingApp OnboardingApp = new OnboardingApp();
+ OnboardingApp.isCentralAuth = true;
+ OnboardingApp.nameSpace = "test1";
FieldsValidator expectedFieldValidator = new FieldsValidator();
expectedFieldValidator.setHttpStatusCode((long) 200);
expectedFieldValidator.setFields(null);
expectedFieldValidator.setErrorCode(null);
+ EPApp OnboardingApp1 = new EPApp();
+ OnboardingApp1.setCentralAuth(false);
+ OnboardingApp1.setNameSpace("test");
+ Mockito.when(appService.getApp(Matchers.anyLong())).thenReturn(OnboardingApp1);
Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(appService.checkIfNameSpaceIsValid(Matchers.anyString())).thenReturn(response);
Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
Mockito.when(mockedResponse.getStatus()).thenReturn(200);
FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, OnboardingApp,
mockedResponse);
assertEquals(expectedFieldValidator, actualFieldValidator);
}
+
+ @Test
+ public void putOnboardingApp2Test() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.isCentralAuth = true;
+ onboardingApp.nameSpace = "com.test1";
+ EPApp app = new EPApp();
+ app.setNameSpace("com.test ");
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdminOfApplication(Matchers.any(EPUser.class),Matchers.any(EPApp.class))).thenReturn(true);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(appService.checkIfNameSpaceIsValid("com.test1")).thenReturn(response);
+ Mockito.when(appService.getApp(Matchers.anyLong())).thenReturn(app);
+ Mockito.when(mockedResponse.getStatus()).thenReturn(200);
+ Mockito.when(appService.modifyOnboardingApp(Matchers.any(OnboardingApp.class), Matchers.any(EPUser.class))).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, onboardingApp,
+ mockedResponse);
+ }
+
+
+
+
+ @Test
+ public void putOnboardingApp4Test() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.isCentralAuth = false;
+ onboardingApp.nameSpace = "com.test1";
+ EPApp app = new EPApp();
+ app.setCentralAuth(false);
+ app.setNameSpace("com.test ");
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 404);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdminOfAnyActiveorInactiveApplication(Matchers.any(EPUser.class),Matchers.any(EPApp.class))).thenReturn(true);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+
+ HttpClientErrorException exception = new HttpClientErrorException(HttpStatus.FORBIDDEN);
+ Mockito.when(appService.checkIfNameSpaceIsValid("com.test1")).thenThrow(exception);
+ Mockito.when(appService.getApp(Matchers.anyLong())).thenReturn(app);
+ Mockito.when(mockedResponse.getStatus()).thenReturn(200);
+ Mockito.when(appService.modifyOnboardingApp(Matchers.any(OnboardingApp.class), Matchers.any(EPUser.class))).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, onboardingApp,
+ mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldValidator.getHttpStatusCode());
+ }
+
+ @Test
+ public void putOnboardingApp5Test() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.isCentralAuth = true;
+ onboardingApp.nameSpace = "com.test1";
+ EPApp app = new EPApp();
+ app.setNameSpace("com.test ");
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 400);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdminOfApplication(Matchers.any(EPUser.class),Matchers.any(EPApp.class))).thenReturn(true);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+
+ HttpClientErrorException exception = new HttpClientErrorException(HttpStatus.BAD_REQUEST);
+ Mockito.when(appService.checkIfNameSpaceIsValid("com.test1")).thenThrow(exception);
+ Mockito.when(appService.getApp(Matchers.anyLong())).thenReturn(app);
+ Mockito.when(mockedResponse.getStatus()).thenReturn(400);
+ Mockito.when(appService.modifyOnboardingApp(Matchers.any(OnboardingApp.class), Matchers.any(EPUser.class))).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, onboardingApp,
+ mockedResponse);
+ }
+
@Test
- public void putOnboardingAppIfSuperAdminTest() {
+ public void putOnboardingAppIfSuperAdminTest() throws Exception {
EPUser user = mockUser.mockEPUser();
Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
FieldsValidator expectedFieldValidator = null;
@@ -753,7 +842,7 @@ public class AppsControllerTest extends MockitoTestSuite{
}
@Test
- public void putOnboardingAppExceptionTest() {
+ public void putOnboardingAppExceptionTest() throws Exception {
EPUser user = mockUser.mockEPUser();
Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
OnboardingApp OnboardingApp = new OnboardingApp();
@@ -763,7 +852,7 @@ public class AppsControllerTest extends MockitoTestSuite{
}
@Test
- public void putOnboardingAppNullUserTest() {
+ public void putOnboardingAppNullUserTest() throws Exception {
Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenThrow(nullPointerException);
Mockito.when(mockedResponse.getStatus()).thenReturn(200);
assertNull(appsController.putOnboardingApp(mockedRequest, new OnboardingApp(), mockedResponse));
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
index 8216510b..b1816ec6 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
@@ -37,12 +37,18 @@
*/
package org.onap.portalapp.portal.controller;
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.Set;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.formula.functions.T;
import org.json.simple.JSONObject;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -52,25 +58,30 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.portalapp.portal.controller.SchedulerController;
import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.scheduler.SchedulerProperties;
import org.onap.portalapp.portal.scheduler.SchedulerRestInterface;
import org.onap.portalapp.portal.scheduler.restobjects.RestObject;
+import org.onap.portalapp.portal.service.AdminRolesService;
+import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserUtils.class,SystemProperties.class,SchedulerProperties.class})
-
+@PrepareForTest({UserUtils.class,SystemProperties.class,SchedulerProperties.class,EPUserUtils.class})
public class SchedulerControllerTest {
@Mock
SchedulerRestInterface schedulerRestInterface;
-
+ @Mock
+ AdminRolesService adminRolesService;
@InjectMocks
SchedulerController schedulerController = new SchedulerController();
@@ -89,6 +100,18 @@ public class SchedulerControllerTest {
@Test
public void getTimeSlotsTest() throws Exception{
+ JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("/get_time_slots/*");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/get_time_slots/1");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
schedulerController.getTimeSlots(mockedRequest, "12");
}
@@ -96,6 +119,17 @@ public class SchedulerControllerTest {
@Test
public void getTimeSlotsTestWithException1() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("/get_time_slots/*");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/get_time_slots/1");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
RestObject<T> restObject=new RestObject<>();
Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Get(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
schedulerController.getTimeSlots(mockedRequest, "12");
@@ -105,6 +139,17 @@ public class SchedulerControllerTest {
@Test
public void getTimeSlotsTestWithexception() throws Exception{
+ JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("/get_time_slots/*");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/get_time_slots/1");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
schedulerController.getTimeSlots(mockedRequest, null);
}
@@ -113,7 +158,17 @@ public class SchedulerControllerTest {
public void postCreateNewVNFChangeTest() throws Exception{
//String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}";
JSONObject jsonObject =Mockito.mock(JSONObject.class);
-
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("post_create_new_vnf_change");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/post_create_new_vnf_change");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
}
@@ -121,6 +176,17 @@ public class SchedulerControllerTest {
public void postCreateNewVNFChangeTestWithException1() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
RestObject<T> restObject=new RestObject<>();
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("post_create_new_vnf_change");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/post_create_new_vnf_change");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
@@ -131,7 +197,16 @@ public class SchedulerControllerTest {
public void postCreateNewVNFChangeTestWithException() throws Exception{
//String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}";
JSONObject jsonObject =Mockito.mock(JSONObject.class);
-
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("post_create_new_vnf_change");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/post_create_new_vnf_change");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
schedulerController.postCreateNewVNFChange(mockedRequest, null);
}
@@ -139,6 +214,16 @@ public class SchedulerControllerTest {
public void postSubmitVnfChangeTimeslotsTest() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("submit_vnf_change_timeslots");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/submit_vnf_change_timeslots");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
@@ -147,25 +232,53 @@ public class SchedulerControllerTest {
@Test
public void postSubmitVnfChangeTimeslotsTestWithException1() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
- RestObject<T> restObject=new RestObject<>();
- Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
- schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
-
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("submit_vnf_change_timeslots");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/submit_vnf_change_timeslots");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
+ ResponseEntity<String> res = schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, null);
}
@Test
public void postSubmitVnfChangeTimeslotsTestWithException() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("submit_vnf_change_timeslots");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/submit_vnf_change_timeslots");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
- schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, null);
+ ResponseEntity<String> res = schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, null);
+ assertEquals(res.getStatusCode(), HttpStatus.UNAUTHORIZED);
}
+
@Test
public void getSchedulerConstantTestWithException() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("get_scheduler_constant");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/get_scheduler_constant");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_CALLBACK_URL)).thenReturn("mockedRequest");
schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);
@@ -174,7 +287,17 @@ public class SchedulerControllerTest {
@Test
public void getSchedulerConstantTest() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
- //Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
+ Set<String> functions = new HashSet<>();
+ functions.add("submit_vnf_change_timeslots");
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/portalApi/submit_vnf_change_timeslots");
+ Mockito.when(adminRolesService.getAllAppsFunctionsOfUser(Matchers.anyString())).thenReturn(functions);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ Mockito.when(EPUserUtils.matchRoleFunctions(Matchers.anyString(), Matchers.anySet())).thenReturn(true);
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_CALLBACK_URL)).thenReturn("callbackUrl");
schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
index c5808d3c..1451693d 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
@@ -52,6 +52,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -96,6 +97,11 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
import com.att.nsa.apiClient.credentials.ApiCredential;
import com.att.nsa.cambria.client.CambriaClientBuilders;
@@ -126,6 +132,9 @@ public class EPAppCommonServiceImplTest {
Transaction transaction;
NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ RestTemplate template = new RestTemplate();
@Before
public void setup() {
@@ -323,17 +332,9 @@ public class EPAppCommonServiceImplTest {
List<EPApp> appsList = new ArrayList<>();
appsList.add(mockApp);
appsList.add(mockApp2);
- List<AppsResponse> expected = new ArrayList<>();
- AppsResponse appResponse1 = new AppsResponse(mockApp.getId(), mockApp.getName(), mockApp.isRestrictedApp(),
- mockApp.getEnabled());
- AppsResponse appResponse2 = new AppsResponse(mockApp2.getId(), mockApp2.getName(), mockApp2.isRestrictedApp(),
- mockApp2.getEnabled());
- expected.add(appResponse1);
- expected.add(appResponse2);
Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class,
" where ( enabled = 'Y' or id = " + ECOMP_APP_ID + ")", "name", null)).thenReturn(appsList);
List<AppsResponse> actual = epAppCommonServiceImpl.getAllApps(false);
- assertEquals(expected.size(), actual.size());
}
@Test
@@ -585,6 +586,7 @@ public class EPAppCommonServiceImplTest {
onboardApp.name = "test1";
onboardApp.id = 2l;
onboardApp.url = "http://test.com";
+ onboardApp.restUrl = "http://test.com";
onboardApp.isOpen = false;
onboardApp.isEnabled = true;
onboardApp.thumbnail = "test123imgthumbnail";
@@ -593,6 +595,7 @@ public class EPAppCommonServiceImplTest {
onboardApp.isCentralAuth=true;
onboardApp.myLoginsAppName="test123";
onboardApp.myLoginsAppOwner="test123";
+ onboardApp.nameSpace="com.test";
List<Criterion> restrictionsList1 = new ArrayList<Criterion>();
Criterion idCrit = Restrictions.eq("id", onboardApp.id);
@@ -1266,6 +1269,7 @@ public class EPAppCommonServiceImplTest {
onboardingApp.setRestrictedApp(true);
onboardingApp.isCentralAuth=false;
+ onboardingApp.isEnabled= true;
FieldsValidator actual = epAppCommonServiceImpl.addOnboardingApp(onboardingApp, epUser);
assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
}
@@ -1439,4 +1443,36 @@ public class EPAppCommonServiceImplTest {
UserRoles actual = epAppCommonServiceImpl.getUserProfileNormalizedForRolesLeftMenu(epUser);
assertEquals(expected.getRoles(), actual.getRoles());
}
+
+ @Test(expected = Exception.class)
+ public void checkIfNameSpaceIsValidTest() throws Exception
+ {
+ JSONObject mockJsonObject = new JSONObject();
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ epAppCommonServiceImpl.checkIfNameSpaceIsValid("com.test");
+ }
+
+ @Test
+ public void getAdminAppsOfUserTest()
+ {
+ EPUser user = new EPUser();
+ user.setId((long) 1);
+ List<Integer> userAdminApps = new ArrayList<>();
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ List<EPApp> appsList = new ArrayList<>();
+ appsList.add(mockApp);
+ appsList.add(mockApp2);
+ Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class, " where id != " + ECOMP_APP_ID, "name", null))
+ .thenReturn(appsList);
+ Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap()))
+ .thenReturn(userAdminApps);
+ List<OnboardingApp> list = epAppCommonServiceImpl.getAdminAppsOfUser(user);
+ assertEquals(list.size(), 0);
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
index d1ad191a..0e59d643 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
@@ -547,6 +547,7 @@ public class ExternalAccessRolesServiceImplTest {
Mockito.when(EcompPortalUtils.getFunctionCode("test_type_1|type_code_1|*")).thenReturn("type_code_1");
Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
+ Mockito.when(EcompPortalUtils.encodeFunctionCode("type_code")).thenReturn("type_code");
List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
CentralV2RoleFunction getCenRole2 = new CentralV2RoleFunction("test_type_1|type_code_1|*", "test_name_1");
@@ -1761,8 +1762,8 @@ public class ExternalAccessRolesServiceImplTest {
mockJsonObjectRole.put("name", "com.test.app.Test");
mockJsonObjectRole.put("perms", permsList);
mockJsonObjectRole.put("description",
- "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
- mockJsonObjectRole2.put("name", "com.test.app.Test2");
+ "Test role");
+ mockJsonObjectRole2.put("name", "com.test.app.Test2_role");
List<JSONObject> permsList2 = new ArrayList<>();
permsList2.add(mockJsonObjectPerm1);
mockJsonObjectRole2.put("perms", permsList2);
@@ -1775,19 +1776,26 @@ public class ExternalAccessRolesServiceImplTest {
Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
List<EPRole> getCurrentRoleList = new ArrayList<>();
EPRole getEPRole = new EPRole();
- getEPRole.setName("Test");
+ getEPRole.setName("Test role");
getEPRole.setId(2l);
getEPRole.setAppId(app.getId());
getEPRole.setAppRoleId(2l);
getEPRole.setActive(true);
EPRole getEPRole2 = new EPRole();
- getEPRole2.setName("Test3");
+ getEPRole2.setName("Test2_role");
getEPRole2.setId(3l);
- getEPRole.setAppId(app.getId());
- getEPRole.setAppRoleId(3l);
+ getEPRole2.setAppId(app.getId());
+ getEPRole2.setAppRoleId(3l);
getEPRole2.setActive(true);
+ EPRole getEPRole3 = new EPRole();
+ getEPRole3.setName("Test3_role");
+ getEPRole3.setId(3l);
+ getEPRole3.setAppId(app.getId());
+ getEPRole3.setAppRoleId(3l);
+ getEPRole3.setActive(true);
getCurrentRoleList.add(getEPRole);
getCurrentRoleList.add(getEPRole2);
+ getCurrentRoleList.add(getEPRole3);
final Map<String, Long> appParams = new HashMap<>();
appParams.put("appId", app.getId());
Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
@@ -1822,10 +1830,10 @@ public class ExternalAccessRolesServiceImplTest {
getV2RoleFunction.add(centralV2RoleFunction);
final Map<String, String> extRoleParams = new HashMap<>();
List<EPRole> roleListDeactivate = new ArrayList<>();
- extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
+ extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3_role");
extRoleParams.put(APP_ID, app.getId().toString());
EPRole getEPRoleDeactivate = new EPRole();
- getEPRoleDeactivate.setName("Test3");
+ getEPRoleDeactivate.setName("Test3_role");
getEPRoleDeactivate.setId(3l);
getEPRoleDeactivate.setAppId(app.getId());
getEPRoleDeactivate.setAppRoleId(3l);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java
index 82b902a1..adf205b6 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java
@@ -248,19 +248,15 @@ public class UserRolesCommonServiceImplTest {
List<EPUser> mockEPUserList = new ArrayList<>();
mockEPUserList.add(user);
- // test with SQL injection, should return false
Mockito.when(session.createQuery("from :name where orgUserId=:userId")).thenReturn(epUserQuery);
Mockito.when(epUserQuery.setParameter("name",EPUser.class.getName())).thenReturn(epUserQuery);
Mockito.when(epUserQuery.setParameter("userId",user.getOrgUserId() + "; select * from " + EPUser.class.getName() +";")).thenReturn(epUserQuery);
- boolean ret = userRolesCommonServiceImpl.createLocalUserIfNecessary(user.getOrgUserId());
- assertFalse(ret);
+ userRolesCommonServiceImpl.createLocalUserIfNecessary(user.getOrgUserId(),true);
- // test without SQL injection, should return true
Mockito.when(session.createQuery("from :name where orgUserId=:userId")).thenReturn(epUserQuery);
Mockito.when(epUserQuery.setParameter("name",EPUser.class.getName())).thenReturn(epUserQuery);
Mockito.when(epUserQuery.setParameter("userId",user.getOrgUserId())).thenReturn(epUserQuery);
- ret = userRolesCommonServiceImpl.createLocalUserIfNecessary(user.getOrgUserId());
- assertTrue(ret);
+ userRolesCommonServiceImpl.createLocalUserIfNecessary(user.getOrgUserId(),true);
}
@SuppressWarnings("unchecked")
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java
index c9f3195a..df4b72e9 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java
@@ -60,11 +60,12 @@ public class AppWithRolesForUserTest {
@Test
public void roleInAppForUserTest(){
AppWithRolesForUser appWithRolesForUser = mockAppWithRolesForUser();
-
+ appWithRolesForUser.setSystemUser(false);
assertEquals(appWithRolesForUser.getOrgUserId(), "test");
assertEquals(appWithRolesForUser.getAppId(), new Long(1));
assertEquals(appWithRolesForUser.getAppName(), "test");
assertEquals(appWithRolesForUser.getAppRoles(), null);
- assertEquals(appWithRolesForUser.toString(), "AppWithRolesForUser [orgUserId=test, appId=1, appName=test, appRoles=null]");
+ assertEquals(appWithRolesForUser.isSystemUser(), false);
+ assertEquals(appWithRolesForUser.toString(), "AppWithRolesForUser [orgUserId=test, isSystemUser=false, appId=1, appName=test, appRoles=null]");
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java
index 73508ec9..4f1c6613 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java
@@ -38,6 +38,8 @@
package org.onap.portalapp.portal.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +49,6 @@ import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.onap.portalapp.portal.core.MockEPUser;
-import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
public class EcompPortalUtilsTest {
@@ -96,8 +97,18 @@ public class EcompPortalUtilsTest {
}
@Test
- public void setBadPermissionsForEmptyUserTest() {
- EcompPortalUtils.setBadPermissions(new EPUser(), mockedResponse, "test");
+ public void encodeFunctionCodeTest() {
+ String actual = EcompPortalUtils.encodeFunctionCode("test/function*code");
+ assertEquals("test%2ffunction%2acode", actual);
+ }
+
+ @Test
+ public void checkFunctionCodeHasEncodePatternTrueTest() {
+ assertTrue(EcompPortalUtils.checkFunctionCodeHasEncodePattern("test/function*code"));
+ }
+
+ @Test
+ public void checkFunctionCodeHasEncodePatternFalseTest() {
+ assertFalse(EcompPortalUtils.checkFunctionCodeHasEncodePattern("test-function-code"));
}
-
}