Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KD23243 committed Sep 24, 2024
1 parent 3838e4b commit 7817051
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.wso2.carbon.identity.scim2.common.group;

import org.apache.commons.lang.StringUtils;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockedConstruction;
Expand Down Expand Up @@ -75,7 +74,6 @@ public class SCIMGroupHandlerTest {
private MockedStatic<SCIMCommonUtils> scimCommonUtils;
private MockedStatic<IdentityDatabaseUtil> identityDatabaseUtil;
private MockedStatic<IdentityTenantUtil> identityTenantUtil;
private MockedStatic<StringUtils> stringUtils;

@BeforeMethod
public void setUp() {
Expand All @@ -84,15 +82,13 @@ public void setUp() {
scimCommonUtils = mockStatic(SCIMCommonUtils.class);
identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class);
identityTenantUtil = mockStatic(IdentityTenantUtil.class);
stringUtils = mockStatic(StringUtils.class);
}

@AfterMethod
public void tearDown() throws Exception {
scimCommonUtils.close();
identityDatabaseUtil.close();
identityTenantUtil.close();
stringUtils.close();
}

@Test
Expand Down Expand Up @@ -181,13 +177,12 @@ public void testGetGroupName() throws Exception {

when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
when(connection.prepareStatement(anyString())).thenReturn(mockedPreparedStatement);
when(StringUtils.isNotEmpty(nullable(String.class))).thenReturn(true);
when(SCIMCommonUtils.getPrimaryFreeGroupName(nullable(String.class))).thenReturn("directors");
when(mockedPreparedStatement.executeQuery()).thenReturn(resultSet);
when(mockedGroupDAO.getGroupNameById(1, "5")).thenReturn("directors");
when(resultSet.next()).thenReturn(true).thenReturn(false);
when(resultSet.getString(1)).thenReturn("roleName");
assertEquals(new SCIMGroupHandler(1).getGroupName("5"), "directors", "asserting for existance");

when(StringUtils.isNotEmpty(nullable(String.class))).thenReturn(false);
assertNull(new SCIMGroupHandler(1).getGroupName("NON_EXISITNG_GROUP_NAME"), "asserting for non existance");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand Down Expand Up @@ -362,7 +369,7 @@ public Object[][] groupName() throws Exception {
@Test(dataProvider = "getGroupException")
public void testGetGroupWithExceptions(String roleName, String userStoreDomain) throws Exception {

AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class);
Field field = AbstractUserStoreManager.class.getDeclaredField("userStoreManagerHolder");
field.setAccessible(true);
field.set(mockedUserStoreManager, new HashMap<String, UserStoreManager>());
Expand Down Expand Up @@ -423,7 +430,7 @@ public void testListGroupsWithFilter(String filter, String roleName, String user

mockedUserStoreManager = mock(AbstractUserStoreManager.class);

AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class);
Field field = AbstractUserStoreManager.class.getDeclaredField("userStoreManagerHolder");
field.setAccessible(true);
field.set(mockedUserStoreManager, new HashMap<String, UserStoreManager>());
Expand Down Expand Up @@ -1450,7 +1457,7 @@ public void testGetUserWhenSCIMisDisabled() throws Exception {
scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.ID_URI, USERID_LOCAL_CLAIM);

when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
mockedUserStoreManager = mock(AbstractUserStoreManager.class);
SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager,
mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
org.wso2.carbon.user.core.common.User user = mock(org.wso2.carbon.user.core.common.User.class);
Expand Down Expand Up @@ -1485,7 +1492,7 @@ public void testDeleteUserWithInvalidUserId() throws Exception {
List<org.wso2.carbon.user.core.common.User> coreUsers = new ArrayList<>();

when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserStoreManager.getUserListWithID(anyString(), anyString(), anyString())).thenReturn(coreUsers);
SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager,
mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Expand All @@ -1507,7 +1514,7 @@ public void testDeleteUserWhenSCIMisDisabled() throws Exception {
coreUser.setUserStoreDomain("DomainName");

when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserStoreManager.getUserWithID(anyString(), any(), anyString())).thenReturn(coreUser);
when(mockedUserStoreManager.getSecondaryUserStoreManager("DomainName")).thenReturn(mockedUserStoreManager);
when(mockedUserStoreManager.isSCIMEnabled()).thenReturn(false);
Expand All @@ -1530,7 +1537,7 @@ public void testDeleteUserWithUserStoreDomainMismatch() throws Exception {
coreUser.setUserStoreDomain("PRIMARY");

when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserStoreManager.getUserWithID(anyString(), any(), anyString())).thenReturn(coreUser);
SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager,
mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Expand Down Expand Up @@ -1585,7 +1592,7 @@ public void testCreateUserWhenSCIMisDisabled() throws Exception {
SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager,
mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
doThrow(new NotImplementedException()).when(mockedUser).setSchemas(Mockito.any(UserManager.class));
mockedUser.setSchemas(Mockito.mock(UserManager.class));
mockedUser.setSchemas(mock(UserManager.class));
scimUserManager.createUser(user, null);
// This method is for testing of throwing CharonException, hence no assertion.
}
Expand Down Expand Up @@ -1616,7 +1623,7 @@ public void testCreateUserWithExistingUserName(String isLoginIdentifiersEnabled)
when(ApplicationManagementService.getInstance()).thenReturn(applicationManagementService);
when(applicationManagementService.getServiceProvider(anyString(), anyString())).thenReturn(null);

mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserStoreManager.isExistingUserWithID(anyString())).thenReturn(true);
when(mockedUserStoreManager.isExistingUser(anyString())).thenReturn(true);
when(mockedUserStoreManager.getUserList(anyString(), anyString(), nullable(String.class))).thenReturn(existingUserList);
Expand Down Expand Up @@ -1650,7 +1657,7 @@ public void testCreateUserWithConflictingLoginIdentifier() throws Exception {
when(SCIMCommonUtils.convertSCIMtoLocalDialect(anyMap())).thenCallRealMethod();
when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMappings);

mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class);
mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserStoreManager.getUserList(anyString(), anyString(), anyString())).thenReturn(null);
when(mockedUserStoreManager.getSecondaryUserStoreManager(anyString()))
.thenReturn(secondaryUserStoreManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@
import java.util.Map;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand Down

0 comments on commit 7817051

Please sign in to comment.