use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo in project carbon-identity-framework by wso2.
the class RoleDAOTest method testDeleteGroup.
@Test
public void testDeleteGroup() throws Exception {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME);
Connection connection3 = DAOUtils.getConnection(DB_NAME);
Connection connection4 = DAOUtils.getConnection(DB_NAME);
Connection connection5 = DAOUtils.getConnection(DB_NAME);
Connection connection6 = DAOUtils.getConnection(DB_NAME);
Connection connection7 = DAOUtils.getConnection(DB_NAME)) {
roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
mockCacheClearing();
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
RoleBasicInfo role = addRole("role1");
doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
doCallRealMethod().when(roleDAO, "updateGroupListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
mockStatic(IdentityUtil.class);
when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
doReturn(groupNamesMap).when(roleDAO, "getGroupNamesByIDs", eq(groupIDsList), anyString());
roleDAO.updateGroupListOfRole(role.getId(), groupIDsList, null, SAMPLE_TENANT_DOMAIN);
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
doReturn("group1").when(roleDAO, "getGroupNameByID", anyString(), anyString());
roleDAO.deleteGroup("groupID1", SAMPLE_TENANT_DOMAIN);
groupNamesMap.remove("group1");
mockRealmConfiguration();
mockStatic(UserCoreUtil.class);
when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection6);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection7);
doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
List<GroupBasicInfo> groups = roleDAO.getGroupListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
assertEquals(getGroupNamesList(groups), groupNamesList);
}
}
Aggregations