Search in sources :

Example 6 with GroupBasicInfo

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);
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) GroupBasicInfo(org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

GroupBasicInfo (org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)6 Connection (java.sql.Connection)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)2 UserBasicInfo (org.wso2.carbon.identity.role.mgt.core.UserBasicInfo)2 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)2 Role (org.wso2.charon3.core.objects.Role)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)1 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)1 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)1 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)1 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)1 CharonException (org.wso2.charon3.core.exceptions.CharonException)1 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)1 Group (org.wso2.charon3.core.objects.Group)1 User (org.wso2.charon3.core.objects.User)1