diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java index be61bc7a6..089989df0 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java @@ -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 @@ -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; @@ -79,7 +78,8 @@ public class SCIMGroupHandlerTest { private MockedStatic stringUtils; @BeforeMethod - public void setUp() throws Exception { + public void setUp() { + initMocks(this); scimCommonUtils = mockStatic(SCIMCommonUtils.class); identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); @@ -93,7 +93,6 @@ public void tearDown() throws Exception { identityDatabaseUtil.close(); identityTenantUtil.close(); stringUtils.close(); - System.clearProperty(CarbonBaseConstants.CARBON_HOME); } @Test @@ -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); @@ -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. } } diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java index fa52abbc4..76513ea49 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java index 4d2d23921..752e0f73f 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java index ff6d4118e..039b9238a 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java @@ -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 @@ -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; @@ -54,7 +49,6 @@ * Contains the unit test cases for IdentitySCIMManager. */ @Listeners(MockitoTestNGListener.class) -@MockitoSettings(strictness = Strictness.LENIENT) public class IdentitySCIMManagerTest { @Mock @@ -66,12 +60,6 @@ public class IdentitySCIMManagerTest { @Mock UserRealm mockedUserRealm; - @Mock - ClaimManager mockedClaimManager; - - @Mock - AbstractUserStoreManager mockedUserStoreManager; - private SCIMConfigProcessor scimConfigProcessor; private IdentitySCIMManager identitySCIMManager; @@ -84,20 +72,12 @@ 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(); } @@ -105,7 +85,6 @@ public void setUp() throws Exception { public void tearDown() { scimCommonComponentHolder.close(); scimCommonUtils.close(); - System.clearProperty(CarbonBaseConstants.CARBON_HOME); } @Test @@ -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); } @@ -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) { diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerTest.java index 5c0954b7e..65796a7f4 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerTest.java @@ -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 @@ -21,11 +21,11 @@ import org.apache.commons.lang.StringUtils; import org.mockito.Mock; import org.mockito.MockedStatic; -import org.mockito.MockitoAnnotations; +import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; @@ -74,7 +74,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertThrows; import static org.testng.Assert.assertTrue; @@ -88,6 +87,7 @@ /** * Contains the unit test cases for SCIMRoleManager. */ +@Listeners(MockitoTestNGListener.class) public class SCIMRoleManagerTest { private static final String SAMPLE_TENANT_DOMAIN = "carbon.super"; @@ -124,15 +124,9 @@ public class SCIMRoleManagerTest { private MockedStatic scimCommonUtils; private MockedStatic organizationManagementUtil; - @BeforeClass - public void setUpClass() { - - initMocks(this); - } - @BeforeMethod public void setUpMethod() { - MockitoAnnotations.openMocks(this); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); organizationManagementUtil = mockStatic(OrganizationManagementUtil.class); when(SCIMCommonUtils.getSCIMRoleURL(nullable(String.class))).thenReturn(DUMMY_SCIM_URL); @@ -447,26 +441,31 @@ public void testListRolesWithGETInvalidLimit(String nodeType, Integer count) throws IdentityRoleManagementException { Node rootNode = generateNodeBasedOnNodeType(nodeType, null); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> { - Integer countArg = invocationOnMock.getArgument(0); - if (countArg != null && countArg < 0) { - String errorMessage = String.format("Invalid limit requested. Limit value should be " + - "greater than or equal to zero. limit: %s", count); - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); - when(mockRoleManagementService.getRoles(nullable(String.class), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) - .thenAnswer(invocationOnMock -> { - Integer countArg = invocationOnMock.getArgument(1); - if (countArg != null && countArg < 0) { - String errorMessage = String.format("Invalid limit requested. Limit value should be " + - "greater than or equal to zero. limit: %s", count); - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); + + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(nullable(String.class), anyInt(), anyInt(), nullable(String.class), + nullable(String.class), anyString())).thenAnswer(invocationOnMock -> { + Integer countArg = invocationOnMock.getArgument(1); + if (countArg != null && countArg < 0) { + String errorMessage = String.format("Invalid limit requested. Limit value should be " + + "greater than or equal to zero. limit: %s", count); + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> { + Integer countArg = invocationOnMock.getArgument(0); + if (countArg != null && countArg < 0) { + String errorMessage = String.format("Invalid limit requested. Limit value should be " + + "greater than or equal to zero. limit: %s", count); + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } + SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); assertThrows(CharonException.class, () -> roleManager. listRolesWithGET(rootNode, 2, count, null, null)); @@ -486,28 +485,32 @@ public void testListRolesWithGETInvalidOffset(String nodeType, Integer startInde throws IdentityRoleManagementException { Node rootNode = generateNodeBasedOnNodeType(nodeType, null); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> { - Integer startIndexArg = invocationOnMock.getArgument(1); - if (startIndexArg != null && startIndexArg < 0) { - String errorMessage = - "Invalid offset requested. Offset value should be greater " + - "than or equal to zero. offset: " + startIndexArg; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); - when(mockRoleManagementService.getRoles(nullable(String.class), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) - .thenAnswer(invocationOnMock -> { - Integer startIndexArg = invocationOnMock.getArgument(2); - if (startIndexArg != null && startIndexArg < 0) { - String errorMessage = - "Invalid offset requested. offset value should be greater than or " + - "equal to zero. offset: " + startIndexArg; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); + + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(nullable(String.class), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) + .thenAnswer(invocationOnMock -> { + Integer startIndexArg = invocationOnMock.getArgument(2); + if (startIndexArg != null && startIndexArg < 0) { + String errorMessage = + "Invalid offset requested. offset value should be greater than or " + + "equal to zero. offset: " + startIndexArg; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> { + Integer startIndexArg = invocationOnMock.getArgument(1); + if (startIndexArg != null && startIndexArg < 0) { + String errorMessage = + "Invalid offset requested. Offset value should be greater " + + "than or equal to zero. offset: " + startIndexArg; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); assertThrows(CharonException.class, () -> roleManager. @@ -529,13 +532,18 @@ public void testListRolesWithGETUnExpectedServerError(String nodeType, String te throws IdentityRoleManagementException { Node rootNode = generateNodeBasedOnNodeType(nodeType, "name"); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenThrow(unExpectedErrorThrower(tenantDomain, sError, - "Error while listing roles in tenantDomain: ")); - when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), - nullable(String.class), anyString())). - thenThrow(unExpectedErrorThrower(tenantDomain, sError, - "Error while listing roles in tenantDomain: ")); + + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), + nullable(String.class), anyString())). + thenThrow(unExpectedErrorThrower(tenantDomain, sError, + "Error while listing roles in tenantDomain: ")); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenThrow(unExpectedErrorThrower(tenantDomain, sError, + "Error while listing roles in tenantDomain: ")); + } + SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain); assertThrows(CharonException.class, () -> roleManager. listRolesWithGET(rootNode, 2, 2, null, null)); @@ -588,12 +596,15 @@ public void testListRolesWithGETPositive(String nodeType, Object count, String o Node rootNode = generateNodeBasedOnNodeType(nodeType, "name", operation); List roleList = getDummyRoleBasicInfoList(); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> roleList); - when(mockRoleManagementService.getRoles(anyString(), nullable(Integer.class), anyInt(), nullable(String.class), - nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> roleList); - when(mockRoleManagementService.getRolesCount(anyString())).thenAnswer(invocationOnMock -> 5); + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(anyString(), nullable(Integer.class), anyInt(), nullable(String.class), + nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> roleList); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> roleList); + when(mockRoleManagementService.getRolesCount(anyString())).thenAnswer(invocationOnMock -> 5); + } SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); RolesGetResponse rolesResponse = roleManager.listRolesWithGET(rootNode, 2, (Integer) count, null, null); @@ -641,13 +652,41 @@ public void testUpdateRoleUpdateRoleName(String roleId, String oldRoleName, Stri RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName); Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, type); - when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo); - when(mockRoleManagementService.updateUserListOfRole( - eq(roleId), anyList(), anyList(), anyString())).thenReturn(roleBasicInfo); - when(mockRoleManagementService.updateGroupListOfRole(eq(roleId), anyList(), - anyList(), anyString())).thenReturn(roleBasicInfo); - when(mockRoleManagementService.setPermissionsForRole(eq(roleId), anyList(), anyString())). - thenReturn(roleBasicInfo); + + boolean isValidRoleId1 = roleId.equals(SAMPLE_VALID_ROLE_ID); + boolean isValidRoleId2 = roleId.equals(SAMPLE_VALID_ROLE_ID2); + boolean isOldRoleNameValid = oldRoleName.equals(SAMPLE_VALID_ROLE_NAME); + boolean isTenantDomain2 = tenantDomain.equals(SAMPLE_TENANT_DOMAIN2); + boolean isTenantDomain = tenantDomain.equals(SAMPLE_TENANT_DOMAIN); + boolean isNewRoleName2 = newRoleName.equals(SAMPLE_VALID_ROLE_NAME2); + boolean isNewRoleNameValid = newRoleName.equals(SAMPLE_VALID_ROLE_NAME); + + boolean isTypeEmptyDeleted = type.equals("EMPTY_DELETED"); + boolean isTypeEmptyNew = type.equals("EMPTY_NEW"); + boolean isTypeEmptyBoth = type.equals("EMPTY_BOTH"); + boolean isTypeEmptyOldPermission = type.equals("EMPTY_OLD_PERMISSION"); + boolean isTypeEmptyNewPermission = type.equals("NULL_NEW_PERMISSION"); + boolean isTypeAllEmptyPermission = type.equals("ALL_EMPTY_PERMISSION"); + boolean isTypeAllEqualPermission = type.equals("ALL_EQUAL_PERMISSION"); + + if ((isValidRoleId1 && (isNewRoleName2 && isTenantDomain2 || isNewRoleNameValid && isTenantDomain2)) || + (isValidRoleId2 && isOldRoleNameValid && isNewRoleName2 && (isTenantDomain && (isTypeEmptyDeleted || isTypeEmptyNew)))) { + when(mockRoleManagementService.updateUserListOfRole(eq(roleId), anyList(), anyList(), anyString())) + .thenReturn(roleBasicInfo); + when(mockRoleManagementService.updateGroupListOfRole(eq(roleId), anyList(), anyList(), anyString())) + .thenReturn(roleBasicInfo); + + if (isTypeEmptyDeleted || isTypeEmptyNew || isTypeEmptyBoth) { + when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())) + .thenReturn(roleBasicInfo); + } + + if (isTypeEmptyNewPermission || isTypeEmptyOldPermission || + isTypeAllEmptyPermission || isTypeAllEqualPermission) { + when(mockRoleManagementService.setPermissionsForRole(eq(roleId), anyList(), anyString())) + .thenReturn(roleBasicInfo); + } + } SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain); scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]); @@ -901,29 +940,34 @@ public void testListRolesWithPOSTInvalidLimit(String nodeType, Integer count) throws IdentityRoleManagementException { Node rootNode = generateNodeBasedOnNodeType(nodeType, "name"); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> { - Integer countArg = invocationOnMock.getArgument(0); - if (countArg != null && countArg < 0) { - String errorMessage = - "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " - + count; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); - when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) - .thenAnswer(invocationOnMock -> { - Integer countArg = invocationOnMock.getArgument(1); - if (countArg != null && countArg < 0) { - String errorMessage = - "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " - + count; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) + .thenAnswer(invocationOnMock -> { + Integer countArg = invocationOnMock.getArgument(1); + + if (countArg != null && countArg < 0) { + String errorMessage = + "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + + count; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> { + Integer countArg = invocationOnMock.getArgument(0); + if (countArg != null && countArg < 0) { + String errorMessage = + "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + + count; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } + SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); assertThrows(CharonException.class, () -> roleManager. listRolesWithPost(getDummySearchRequest(rootNode, 2, count, null, null))); @@ -943,30 +987,35 @@ public void testListRolesWithPOSTInvalidOffset(String nodeType, Integer startInd throws IdentityRoleManagementException { Node rootNode = generateNodeBasedOnNodeType(nodeType, "name"); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenAnswer(invocationOnMock -> { - Integer startIndexArg = invocationOnMock.getArgument(1); - if (startIndexArg != null && startIndexArg < 0) { - String errorMessage = - "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " - + startIndexArg; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); - when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) - .thenAnswer(invocationOnMock -> { - Integer startIndexArg = invocationOnMock.getArgument(2); + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())) + .thenAnswer(invocationOnMock -> { + Integer startIndexArg = invocationOnMock.getArgument(2); + + if (startIndexArg != null && startIndexArg < 0) { + String errorMessage = + "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + + startIndexArg; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenAnswer(invocationOnMock -> { + Integer startIndexArg = invocationOnMock.getArgument(1); + + if (startIndexArg != null && startIndexArg < 0) { + String errorMessage = + "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + + startIndexArg; + throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); + } + return null; + }); + } - if (startIndexArg != null && startIndexArg < 0) { - String errorMessage = - "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " - + startIndexArg; - throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage); - } - return null; - }); SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); assertThrows(CharonException.class, () -> roleManager. listRolesWithPost(getDummySearchRequest(rootNode, startIndex, 2, null, null))); @@ -987,12 +1036,16 @@ public void testListRolesWithPOSTUnExpectedServerError(String nodeType, String t Node rootNode = generateNodeBasedOnNodeType(nodeType, "name"); - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). - thenThrow(unExpectedErrorThrower(tenantDomain, sError, - "Error while listing roles in tenantDomain: ")); - when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), - nullable(String.class), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, - "Error while listing roles in tenantDomain: ")); + if ("Expression".equals(nodeType)) { + when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), nullable(String.class), + nullable(String.class), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, + "Error while listing roles in tenantDomain: ")); + } else { + when(mockRoleManagementService.getRoles(anyInt(), anyInt(), nullable(String.class), nullable(String.class), anyString())). + thenThrow(unExpectedErrorThrower(tenantDomain, sError, + "Error while listing roles in tenantDomain: ")); + } + SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain); assertThrows(CharonException.class, () -> roleManager. listRolesWithPost(getDummySearchRequest(rootNode, 2, 2, null, null))); @@ -1045,13 +1098,6 @@ public void testListRolesWithPOSTPositive(String nodeType, String operation) Node rootNode = generateNodeBasedOnNodeType(nodeType, "name", operation); - List roleList = getDummyRoleBasicInfoList(); - - when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())). - thenAnswer(invocationOnMock -> roleList); - when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), - anyString(), anyString())).thenAnswer(invocationOnMock -> roleList); - SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN); roleManager.listRolesWithPost(getDummySearchRequest(rootNode, 2, 3, null, null)); assertTrue(true, "listRolesWIthPost run successfully"); diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java index 890de538f..7c0e8f005 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java @@ -82,7 +82,6 @@ public void setUpMethod() { @AfterMethod public void tearDown() { identityUtil.close(); - System.clearProperty(CarbonBaseConstants.CARBON_HOME); } @DataProvider(name = "scimOperations") diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java index e7e9241ce..707c19912 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java @@ -226,7 +226,6 @@ public void tearDown() { scimUserSchemaExtensionBuilder.close(); claimMetadataHandler.close(); resourceManagerUtil.close(); - System.clearProperty(CarbonBaseConstants.CARBON_HOME); } @DataProvider(name = "ClaimData") diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java index 20b6ce6ea..5b81a1e2b 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/test/utils/CommonTestUtils.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/test/utils/CommonTestUtils.java index af4dcc3ea..d19e7f2e2 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/test/utils/CommonTestUtils.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/test/utils/CommonTestUtils.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java index 0fde819e8..997d53496 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java @@ -35,7 +35,12 @@ import java.util.Map; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; public class AdminAttributeUtilTest { diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java index 255f0193e..f8b78d9b2 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java @@ -39,9 +39,14 @@ import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.util.UserCoreUtil; -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.Mockito.mockConstruction; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.testng.Assert.assertEquals; diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AttributeMapperTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AttributeMapperTest.java index f28d963d0..fea6895d8 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AttributeMapperTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AttributeMapperTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AuthenticationSchemaTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AuthenticationSchemaTest.java index 34a025b25..996edb2eb 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AuthenticationSchemaTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AuthenticationSchemaTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java index 493cdb9d0..28886d844 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java @@ -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 diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMConfigProcessorTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMConfigProcessorTest.java index a69b231e9..0c79879ac 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMConfigProcessorTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMConfigProcessorTest.java @@ -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