Search in sources :

Example 26 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpResourceNotFoundException.

// Register with invalid clientId
@Test
public void signUpResourceNotFoundException() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    ResourceNotFoundException exception = new ResourceNotFoundException("registration failed");
    doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
    testPool.signUp(TEST_USER_NAME, "null", TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            assertNotNull(user);
            assertEquals(TEST_USER_NAME, user.getUserId());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
            assertTrue(exception instanceof ResourceNotFoundException);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 27 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpPasswordException.

// Register with invalid password
@Test
public void signUpPasswordException() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    InvalidParameterException exception = new InvalidParameterException("registration failed");
    doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
    testPool.signUp(TEST_USER_NAME, "null", TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertEquals(TEST_USER_NAME, user.getUserId());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
            assertTrue(exception instanceof InvalidParameterException);
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 28 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpUserInCurrentThread.

@Test
public void signUpUserInCurrentThread() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 29 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpUserWithoutPPInCurrentThread.

@Test
public void signUpUserWithoutPPInCurrentThread() throws Exception {
    // Test shared Pinpoint context
    awsKeyValueStorageUtility.put(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1);
    // Test new user pool creation with PP app id.
    CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            assertNull(requestSent.getAnalyticsMetadata());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 30 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpUserWithPPInCurrentThread.

@Test
public void signUpUserWithPPInCurrentThread() throws Exception {
    // Test shared Pinpoint context
    ApplicationProvider.getApplicationContext().getSharedPreferences(TEST_PP_APP_ID_1 + PP_PREFERENCES_AND_FILE_MANAGER_SUFFIX, Context.MODE_PRIVATE).edit().putString(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1).apply();
    // Test new user pool creation with PP app id.
    CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient, TEST_PP_APP_ID_1);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            assertNotNull(requestSent.getAnalyticsMetadata());
            assertEquals(TEST_PP_ENDPOINT_1, requestSent.getAnalyticsMetadata().getAnalyticsEndpointId());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) 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