Search in sources :

Example 41 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInBackgroundThreadInvalidUser.

@Test
public void forgotPasswordInBackgroundThreadInvalidUser() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    InvalidParameterException exception = new InvalidParameterException("password change request failed");
    doThrow(exception).when(mockCSIClient).forgotPassword(any(ForgotPasswordRequest.class));
    // Except to fail
    final FlowTracker tracker;
    tracker = new FlowTracker("onFailure");
    tracker.activate();
    testUser.forgotPasswordInBackground(new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            tracker.setNext("onSuccess");
            doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
            var1.setPassword(TEST_USER_PASSWORD);
            var1.setVerificationCode(TEST_CODE);
            var1.continueTask();
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 42 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderForgotPasswordTest method confirmPasswordInCurrentThread.

@Test
public void confirmPasswordInCurrentThread() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    final FlowTracker tracker;
    tracker = new FlowTracker("onSuccess");
    tracker.activate();
    doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
    testUser.confirmPassword(TEST_CODE, TEST_USER_PASSWORD, new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            // Except to fail
            tracker.setNext("onFailure");
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 43 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInBackground.

@Test
public void forgotPasswordInBackground() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    final FlowTracker tracker;
    tracker = new FlowTracker("getResetCode");
    tracker.activate();
    doReturn(TEST_FORGOT_PASSWORD_RESPONSE).when(mockCSIClient).forgotPassword(any(ForgotPasswordRequest.class));
    testUser.forgotPasswordInBackground(new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            tracker.setNext("onSuccess");
            doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
            var1.setPassword(TEST_USER_PASSWORD);
            var1.setVerificationCode(TEST_CODE);
            var1.continueTask();
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 44 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInBackgroundThreadWrongCode.

@Test
public void forgotPasswordInBackgroundThreadWrongCode() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    final FlowTracker tracker;
    tracker = new FlowTracker("getResetCode");
    tracker.activate();
    doReturn(TEST_FORGOT_PASSWORD_RESPONSE).when(mockCSIClient).forgotPassword(any(ForgotPasswordRequest.class));
    testUser.forgotPasswordInBackground(new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            // Except to fail
            tracker.setNext("onFailure");
            InvalidParameterException exception = new InvalidParameterException("password change request failed");
            doThrow(exception).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
            var1.setPassword(TEST_USER_PASSWORD);
            var1.setVerificationCode(TEST_CODE);
            var1.continueTask();
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 45 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderForgotPasswordTest method init.

@Before
public void init() {
    // Initialization functions
    MockitoAnnotations.initMocks(this);
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set Forgot password result
    TEST_FORGOT_PASSWORD_RESPONSE = new ForgotPasswordResult();
    TEST_FORGOT_PASSWORD_RESPONSE.setCodeDeliveryDetails(new CodeDeliveryDetailsType().withDestination("TestDestination").withDeliveryMedium("TestMedium").withAttributeName("TestAttribute"));
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Before(org.junit.Before)

Aggregations

CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)56 Test (org.junit.Test)41 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)28 ArgumentCaptor (org.mockito.ArgumentCaptor)11 SharedPreferences (android.content.SharedPreferences)9 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)9 GetUserRequest (com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest)8 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)8 CognitoUserAttributes (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes)7 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)7 Before (org.junit.Before)7 CognitoUserCodeDeliveryDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails)6 CognitoUserDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails)6 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)6 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)6 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)6 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)6 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)6 UpdateUserAttributesRequest (com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest)6 ClientConfiguration (com.amazonaws.ClientConfiguration)4