Search in sources :

Example 6 with CognitoUserPool

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

the class CognitoIdentityProviderChangePasswordInstrumentedTest 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);
    awsKeyValueStorageUtility = getAWSKeyValueStorageUtility(testPool);
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) Before(org.junit.Before)

Example 7 with CognitoUserPool

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

the class CognitoIdentityProviderDevicesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    awsKeyValueStorageUtility = getAWSKeyValueStorageUtility(testPool);
    testUser = testPool.getUser(TEST_USER_NAME);
    TEST_VALID_GET_DEVICE_RESPONSE = new GetDeviceResult();
    TEST_VALID_UPDATE_DEVICE_RESPONSE = new UpdateDeviceStatusResult();
    TEST_VALID_LIST_DEVICES_RESPONSE = new ListDevicesResult();
}
Also used : ListDevicesResult(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) GetDeviceResult(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceResult) UpdateDeviceStatusResult(com.amazonaws.services.cognitoidentityprovider.model.UpdateDeviceStatusResult) Before(org.junit.Before)

Example 8 with CognitoUserPool

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

the class CognitoIdentityProviderGetUserTest method getUserAttributeInBackgroundWithCachedTokens.

// Get user attributes - in background
@Test
public void getUserAttributeInBackgroundWithCachedTokens() {
    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_GET_USER_RESULT).when(mockCSIClient).getUser(any(GetUserRequest.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();
    testUser.getDetailsInBackground(new GetDetailsHandler() {

        @Override
        public void onSuccess(CognitoUserDetails details) {
            // Extract the arguments passed to get user API call
            ArgumentCaptor<GetUserRequest> argumentCaptor = ArgumentCaptor.forClass(GetUserRequest.class);
            verify(mockCSIClient).getUser(argumentCaptor.capture());
            GetUserRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed to the API call
            assertNotNull(requestSent);
            assertNotNull(requestSent.getAccessToken());
            // Verify result
            assertNotNull(details);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) GetUserRequest(com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) SharedPreferences(android.content.SharedPreferences) CognitoUserDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 9 with CognitoUserPool

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

the class CognitoIdentityProviderGetUserTest method getUserAttributeInCurrentThreadWithNoCachedTokens.

@Test
public void getUserAttributeInCurrentThreadWithNoCachedTokens() {
    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_GET_USER_RESULT).when(mockCSIClient).getUser(any(GetUserRequest.class));
    testUser.getDetails(new GetDetailsHandler() {

        @Override
        public void onSuccess(CognitoUserDetails details) {
            // Extract the arguments passed to get user API call
            assertTrue(false);
        }

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

Example 10 with CognitoUserPool

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

the class CognitoIdentityProviderGetUserTest method getUserAttributeInBackgroundWithCachedTokensServiceException.

// Get user attributes - in background
@Test
public void getUserAttributeInBackgroundWithCachedTokensServiceException() {
    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).getUser(any(GetUserRequest.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();
    testUser.getDetailsInBackground(new GetDetailsHandler() {

        @Override
        public void onSuccess(CognitoUserDetails details) {
            // Extract the arguments passed to get user API call
            ArgumentCaptor<GetUserRequest> argumentCaptor = ArgumentCaptor.forClass(GetUserRequest.class);
            verify(mockCSIClient).getUser(argumentCaptor.capture());
            GetUserRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed to the API call
            assertNotNull(requestSent);
            assertNotNull(requestSent.getAccessToken());
            // Verify result
            assertNotNull(details);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) GetUserRequest(com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) SharedPreferences(android.content.SharedPreferences) CognitoUserDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) 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