use of com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInBackgroundWithCachedTokens.
// Get user attributes - in background
@Test
public void updateUserAttributeInBackgroundWithCachedTokens() {
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));
// 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.updateAttributesInBackground(attributes, new UpdateAttributesHandler() {
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
// 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(var1);
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithCachedTokens.
// Get user attributes -
@Test
public void updateUserAttributeInCurrentThreadWithCachedTokens() {
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));
// 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) {
// 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(var1);
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
Aggregations