Search in sources :

Example 31 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method init.

@Before
public void init() {
    if (firstTime) {
        // Initialization
        MockitoAnnotations.initMocks(this);
        testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET);
        awsKeyValueStorageUtility = getAWSKeyValueStorageUtility(testPool);
        // Data for tests
        TEST_IN_USER_ATTRIBUTES_LIST = new CognitoUserAttributes();
        TEST_IN_USER_ATTRIBUTES_LIST.addAttribute("email", TEST_USER_EMAIL);
        TEST_IN_USER_ATTRIBUTES_LIST.addAttribute("phone_number", TEST_USER_PHONE);
        TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
        TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
        TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
        TEST_IN_VALIDATION_DATA.put("DummyAttribute_3", "Value4DummyAttribute_3");
        TEST_REGISTER_USER_RESPONSE = new SignUpResult();
        TEST_REGISTER_USER_RESPONSE.setUserConfirmed(true);
        TEST_REGISTER_USER_RESPONSE.setCodeDeliveryDetails(TEST_CODE_DELIVERY_DETAIL);
        firstTime = false;
    }
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Before(org.junit.Before)

Example 32 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpInBackgroundUnexpectedLambdaException.

// Sign-up failure
@Test
public void signUpInBackgroundUnexpectedLambdaException() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    UnexpectedLambdaException exception = new UnexpectedLambdaException("registration failed");
    doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
    testPool.signUpInBackground(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 UnexpectedLambdaException);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) 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 33 with CognitoUserPool

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

the class CognitoIdentityProviderCustomEndPointTest method testForCustomEndpointWhenEmpty.

/**
 * Test that end point is not set for the {@link AmazonCognitoIdentityProviderClient }
 * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called
 * with an empty endpoint
 */
@Test
public void testForCustomEndpointWhenEmpty() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, "");
    verifyZeroInteractions(mockCustomEndpointClient);
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Test(org.junit.Test)

Example 34 with CognitoUserPool

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

the class CognitoIdentityProviderCustomEndPointTest method testForCustomEndpoint.

/**
 * Test that end point is set for the {@link AmazonCognitoIdentityProviderClient } with correct value
 * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called
 * with a valid endpoint
 */
@Test
public void testForCustomEndpoint() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, DUMMY_CUSTOM_ENDPOINT);
    verify(mockCustomEndpointClient).setEndpoint(DUMMY_CUSTOM_ENDPOINT);
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Test(org.junit.Test)

Example 35 with CognitoUserPool

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

the class CognitoIdentityProviderCustomEndPointTest method testForCustomEndpointWhenNull.

/**
 * Test that end point is not set for the {@link AmazonCognitoIdentityProviderClient }
 * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called
 * with a null endpoint
 */
@Test
public void testForCustomEndpointWhenNull() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, null);
    verifyZeroInteractions(mockCustomEndpointClient);
}
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