Search in sources :

Example 16 with CognitoUserPool

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

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithNoCachedTokens.

@Test
public void updateUserAttributeInCurrentThreadWithNoCachedTokens() {
    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
    doReturn(TEST_VALID_UPDATE_USER_RESULT).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributes(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 17 with CognitoUserPool

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

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithCachedTokensServiceException.

// Get user attributes -
@Test
public void updateUserAttributeInCurrentThreadWithCachedTokensServiceException() {
    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("registration failed");
    doThrow(exception).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    // Store tokens in shared preferences
    SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN).commit();
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributes(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        // System.out.println("Exception: "+exception.toString());
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) SharedPreferences(android.content.SharedPreferences) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 18 with CognitoUserPool

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

the class CognitoIdentityProviderConfirmUserTest method init.

@Before
public void init() throws Exception {
    // 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);
    TEST_RESEND_CONFIRM_CODE_RESPONSE = new ResendConfirmationCodeResult();
    TEST_RESEND_CONFIRM_CODE_RESPONSE.setCodeDeliveryDetails(new CodeDeliveryDetailsType().withDestination("TestDestination").withDeliveryMedium("TestMedium").withAttributeName("TestAttribute"));
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Before(org.junit.Before)

Example 19 with CognitoUserPool

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

the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInCurrentThread.

@Test
public void forgotPasswordInCurrentThread() 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.forgotPassword(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 20 with CognitoUserPool

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

the class CognitoIdentityProviderForgotPasswordTest method confirmPasswordInCurrentThreadNoCallback.

@Test
public void confirmPasswordInCurrentThreadNoCallback() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
    try {
        testUser.confirmPassword(TEST_CODE, TEST_USER_PASSWORD, null);
    } catch (final CognitoParameterInvalidException exception) {
        return;
    }
    assertTrue("CognitoParameterInvalidException is not thrown when the callback to confirmPassword in null.", true);
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Test(org.junit.Test)

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