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 1a59e33 commit 3838e4b
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org)
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -27,7 +27,6 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.wso2.carbon.base.CarbonBaseConstants;
import org.wso2.carbon.identity.core.util.IdentityDatabaseUtil;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.scim2.common.DAO.GroupDAO;
Expand Down Expand Up @@ -79,7 +78,8 @@ public class SCIMGroupHandlerTest {
private MockedStatic<StringUtils> stringUtils;

@BeforeMethod
public void setUp() throws Exception {
public void setUp() {

initMocks(this);
scimCommonUtils = mockStatic(SCIMCommonUtils.class);
identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class);
Expand All @@ -93,7 +93,6 @@ public void tearDown() throws Exception {
identityDatabaseUtil.close();
identityTenantUtil.close();
stringUtils.close();
System.clearProperty(CarbonBaseConstants.CARBON_HOME);
}

@Test
Expand Down Expand Up @@ -315,7 +314,6 @@ public void testUpdateRoleName() throws Exception {

@Test(expectedExceptions = IdentitySCIMException.class)
public void testUpdateRoleNameNonExistent() throws Exception {
ResultSet resultSet = mock(ResultSet.class);

when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);

Expand All @@ -327,6 +325,7 @@ public void testUpdateRoleNameNonExistent() throws Exception {

SCIMGroupHandler scimGroupHandler = new SCIMGroupHandler(1);
scimGroupHandler.updateRoleName("NON_EXISTENT_ROLE_NAME", "NEW_ROLE_NAME");
// This method is to test the throwing of an IdentitySCIMException, hence no assertion.
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2021, WSO2 LLC. (http://www.wso2.org)
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2021, WSO2 LLC. (http://www.wso2.org)
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org)
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -20,22 +20,17 @@

import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.quality.Strictness;
import org.mockito.testng.MockitoSettings;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.annotations.Listeners;
import org.mockito.testng.MockitoTestNGListener;
import org.wso2.carbon.base.CarbonBaseConstants;
import org.wso2.carbon.identity.scim2.common.internal.SCIMCommonComponentHolder;
import org.wso2.carbon.identity.scim2.common.test.utils.CommonTestUtils;
import org.wso2.carbon.identity.scim2.common.utils.SCIMCommonUtils;
import org.wso2.carbon.identity.scim2.common.utils.SCIMConfigProcessor;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.claim.ClaimManager;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.charon3.core.exceptions.CharonException;
Expand All @@ -54,7 +49,6 @@
* Contains the unit test cases for IdentitySCIMManager.
*/
@Listeners(MockitoTestNGListener.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class IdentitySCIMManagerTest {

@Mock
Expand All @@ -66,12 +60,6 @@ public class IdentitySCIMManagerTest {
@Mock
UserRealm mockedUserRealm;

@Mock
ClaimManager mockedClaimManager;

@Mock
AbstractUserStoreManager mockedUserStoreManager;

private SCIMConfigProcessor scimConfigProcessor;
private IdentitySCIMManager identitySCIMManager;

Expand All @@ -84,28 +72,19 @@ public void setUp() throws Exception {
scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMUserURL()).thenReturn("http://scimUserUrl:9443");

scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class);
scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService);

scimConfigProcessor = SCIMConfigProcessor.getInstance();
String filePath = Paths
.get(System.getProperty("user.dir"), "src", "test", "resources", "charon-config-test.xml").toString();
scimConfigProcessor.buildConfigFromFile(filePath);
identitySCIMManager = IdentitySCIMManager.getInstance();

when(realmService.getTenantManager()).thenReturn(mockedTenantManager);
when(mockedTenantManager.getTenantId(anyString())).thenReturn(-1234);
when(realmService.getTenantUserRealm(anyInt())).thenReturn(mockedUserRealm);

when(mockedUserRealm.getClaimManager()).thenReturn(mockedClaimManager);
when(mockedUserRealm.getUserStoreManager()).thenReturn(mockedUserStoreManager);
CommonTestUtils.initPrivilegedCarbonContext();
}

@AfterMethod
public void tearDown() {
scimCommonComponentHolder.close();
scimCommonUtils.close();
System.clearProperty(CarbonBaseConstants.CARBON_HOME);
}

@Test
Expand All @@ -125,6 +104,8 @@ public void testGetEncoder() throws Exception {
public void testGetUserManager() throws Exception {

when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService);
when(realmService.getTenantManager()).thenReturn(mockedTenantManager);
when(realmService.getTenantUserRealm(anyInt())).thenReturn(mockedUserRealm);
UserManager userManager = identitySCIMManager.getUserManager();
assertNotNull(userManager);
}
Expand All @@ -144,9 +125,11 @@ public void testGetUserManagerWithException() throws Exception {
@Test
public void testGetUserManagerWithException2() throws Exception {

when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService);
when(realmService.getTenantManager()).thenReturn(mockedTenantManager);
when(mockedTenantManager.getTenantId(anyString())).thenThrow(new UserStoreException());

try {
when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService);
when(mockedTenantManager.getTenantId(anyString())).thenThrow(new UserStoreException());
identitySCIMManager.getUserManager();
fail("getUserManager() method should have thrown a CharonException");
} catch (CharonException e) {
Expand Down
Loading

0 comments on commit 3838e4b

Please sign in to comment.