From d6a5683e5dd9a7546b0f6f9fe3bb97ed1b0b0f0a Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Wed, 18 Sep 2024 15:27:16 +0530 Subject: [PATCH] Add connector config update tests --- .../connector/UserClaimUpdateConfigImpl.java | 1 - .../UserClaimUpdateConfigImplTest.java | 9 +++++++++ .../MobileNumberVerificationHandlerTest.java | 18 ++++++++++++++++++ .../UserEmailVerificationHandlerTest.java | 4 ++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImpl.java b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImpl.java index 0165bbec9..415157d40 100644 --- a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImpl.java +++ b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImpl.java @@ -74,7 +74,6 @@ public class UserClaimUpdateConfigImpl implements IdentityConnectorConfig { private static final String VERIFICATION_ON_UPDATE_ELEMENT = "VerificationOnUpdate"; private static final String NOTIFICATION_ON_UPDATE_ELEMENT = "NotificationOnUpdate"; private static final String ENABLE_MOBILE_VERIFICATION_PRIVILEGED_USER = "EnableVerificationByPrivilegedUser"; - private static final String ENABLE_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_ELEMENT = "EnableMultipleEmailsAndMobileNumbers"; private static String enableEmailVerificationOnUpdateProperty = null; private static String enableSendOTPInEmailProperty = null; private static String useUppercaseCharactersInOTPProperty = null; diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImplTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImplTest.java index ed38fc30f..952009681 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImplTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/UserClaimUpdateConfigImplTest.java @@ -21,6 +21,7 @@ import org.apache.axiom.om.OMElement; import org.mockito.MockedStatic; import org.mockito.Mockito; +import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; @@ -29,6 +30,7 @@ import org.wso2.carbon.identity.core.util.IdentityCoreConstants; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; +import org.wso2.carbon.identity.application.common.model.Property; import java.util.ArrayList; import java.util.HashMap; @@ -259,4 +261,11 @@ public void testGetDefaultProperties() throws IdentityGovernanceException { assertEquals(defaultPropertyValues.size(), propertyNames.length - 1, "Maps are not equal as" + " their size differs."); } + + @Test + public void testGetMetaData() { + + Map metaData = userClaimUpdateConfig.getMetaData(); + Assert.assertEquals(metaData.size(), 10); + } } diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/MobileNumberVerificationHandlerTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/MobileNumberVerificationHandlerTest.java index d4104ca63..77a4795cd 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/MobileNumberVerificationHandlerTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/MobileNumberVerificationHandlerTest.java @@ -370,6 +370,24 @@ public void testAddNewMobileToVerifiedList() throws Exception { } catch (Exception e) { Assert.assertTrue(e instanceof IdentityEventClientException); } + + // Case 3: Added new number is existing primary mobile number. + String newVerifiedMobileNumbers3 = existingNumber1 + "," + newMobileNumber; + Event event3 = createEvent(IdentityEventConstants.Event.PRE_SET_USER_CLAIMS, + IdentityRecoveryConstants.FALSE, + newVerifiedMobileNumbers3, null, null); + + mockExistingVerifiedNumbersList(new ArrayList<>(Arrays.asList(existingNumber1))); + mockExistingNumbersList(new ArrayList<>(Arrays.asList(existingNumber1))); + mockExistingPrimaryMobileNumber(newMobileNumber); + + mobileNumberVerificationHandler.handleEvent(event3); + + Map userClaims3 = getUserClaimsFromEvent(event3); + Assert.assertTrue( + StringUtils.contains(userClaims3.get(IdentityRecoveryConstants.MOBILE_NUMBERS_CLAIM), newMobileNumber)); + Assert.assertTrue(StringUtils.contains(userClaims3.get(IdentityRecoveryConstants.VERIFIED_MOBILE_NUMBERS_CLAIM), + newMobileNumber)); } @Test(description = "POST_SET_USER_CLAIMS: Verification enabled, Multi-attribute enabled") diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/UserEmailVerificationHandlerTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/UserEmailVerificationHandlerTest.java index f1a47cb1f..d83ade11c 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/UserEmailVerificationHandlerTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/handler/UserEmailVerificationHandlerTest.java @@ -501,7 +501,7 @@ public void testHandleEventPostAddUserVerifyEmailClaim() throws IdentityEventExc any())); } - @Test(priority = 99) + @Test public void testHandleEventPostAddUserAskPasswordClaimNotificationInternallyManaged() throws IdentityEventException, IdentityRecoveryException { @@ -528,7 +528,7 @@ public void testHandleEventPostAddUserAskPasswordClaimNotificationInternallyMana any())); } - @Test(priority = 100) + @Test public void testHandleEventPostAddUserAskPasswordClaimNotificationExternallyManaged() throws IdentityEventException, IdentityRecoveryException {