use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderGetUserTest method getUserAttributeInBackgroundWithNoCachedTokens.
@Test
public void getUserAttributeInBackgroundWithNoCachedTokens() {
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.getDetailsInBackground(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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderGetUserTest method getUserAttributeInCurrentThreadWithCachedTokens.
// Get user attributes -
@Test
public void getUserAttributeInCurrentThreadWithCachedTokens() {
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.getDetails(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);
}
});
}
Aggregations