import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail;
import org.onap.portalapp.portal.domain.ExternalSystemAccess;
-import org.onap.portalapp.portal.transport.AppWithRolesForUser;
-import org.onap.portalapp.portal.transport.CentralV2Role;
-import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles;
-import org.onap.portalapp.portal.transport.EcompUserAppRoles;
-import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
-import org.onap.portalapp.portal.transport.FieldsValidator;
-import org.onap.portalapp.portal.transport.FunctionalMenuItem;
-import org.onap.portalapp.portal.transport.FunctionalMenuRole;
-import org.onap.portalapp.portal.transport.RemoteRole;
-import org.onap.portalapp.portal.transport.RemoteUserWithRoles;
-import org.onap.portalapp.portal.transport.RoleInAppForUser;
-import org.onap.portalapp.portal.transport.UserApplicationRoles;
+import org.onap.portalapp.portal.transport.*;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
import org.onap.portalapp.portal.utils.EcompPortalUtils;
import org.onap.portalapp.portal.utils.PortalConstants;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@Mock
Transaction transaction;
+
+ @Mock
+ AdminRolesService adminRolesService;
@InjectMocks
UserRolesCommonServiceImpl userRolesCommonServiceImpl = new UserRolesCommonServiceImpl();
Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
List<RoleInAppForUser> mockRoleInAppForUserList = getMockedRoleInAppUserList();
List<CentralV2Role> mockCenV2Role = new ArrayList<>();
- CentralV2Role cenV2Role = new CentralV2Role(1l, null, null, null, null, null, "test1", true, null,
- new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
- CentralV2Role cenV2Role2 = new CentralV2Role(16l, null, null, null, null, null, "test2", true, null,
- new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
+ CentralV2Role cenV2Role = new CentralV2Role.CentralV2RoleBuilder().setId(1l).setCreated(null).setModified(null)
+ .setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test1").setActive(true)
+ .setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+ .setParentRoles(new TreeSet<>()).createCentralV2Role();
+ CentralV2Role cenV2Role2 = new CentralV2Role.CentralV2RoleBuilder().setId(16l).setCreated(null)
+ .setModified(null).setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test2")
+ .setActive(true).setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+ .setParentRoles(new TreeSet<>()).createCentralV2Role();
mockCenV2Role.add(cenV2Role);
mockCenV2Role.add(cenV2Role2);
Mockito.when(externalAccessRolesServiceImpl.getRolesForApp(mockApp.getUebKey())).thenReturn(mockCenV2Role);
Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
- mockRoleInAppForUser.setIsApplied(false);
+ mockRoleInAppForUser.setIsApplied(true);
mockRoleInAppForUser.setRoleId(333l);
mockRoleInAppForUser.setRoleName("test1");
RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
- mockRoleInAppForUser2.setIsApplied(false);
+ mockRoleInAppForUser2.setIsApplied(true);
mockRoleInAppForUser2.setRoleId(777l);
mockRoleInAppForUser2.setRoleName("test2");
RoleInAppForUser mockRoleInAppForUser3 = new RoleInAppForUser();
Mockito.when(session.createSQLQuery("update fn_role set app_id = null where app_id = 1 "))
.thenReturn(epsetAppWithUserRoleUpdateEPRoleQuery);
ExternalRequestFieldsValidator actual = userRolesCommonServiceImpl.setAppWithUserRoleStateForUser(user, mockWithRolesForUser);
- assertFalse(actual.isResult());
+ assertTrue(actual.isResult());
}
private List<EcompUserAppRoles> getCurrentUserRoles(EPUser user, EPApp mockApp) {
mockUserApplicationRoles2.setRoles(mockRemoteRoleList2);
mockUserApplicationRolesList.add(mockUserApplicationRoles);
mockUserApplicationRolesList.add(mockUserApplicationRoles2);
- Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null))
+ Map<String, Object> params = new HashMap<>();
+ params.put("id", 1l);
+ params.put("active", true);
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null))
.thenReturn(mockEpUserList);
assertEquals(userRolesCommonServiceImpl.getUsersFromAppEndpoint(1l).size(),
mockUserApplicationRolesList.size());