use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithNoCachedTokens.
@Test
public void updateUserAttributeInCurrentThreadWithNoCachedTokens() {
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));
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.addAttribute("TestAttribute1", "TestData1");
attributes.addAttribute("TestAttribute2", "TestData2");
testUser.updateAttributes(attributes, new UpdateAttributesHandler() {
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
assertNotNull(var1);
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithCachedTokensServiceException.
// Get user attributes -
@Test
public void updateUserAttributeInCurrentThreadWithCachedTokensServiceException() {
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).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) {
assertNotNull(var1);
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
// System.out.println("Exception: "+exception.toString());
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderConfirmUserTest method init.
@Before
public void init() throws Exception {
// Initialization functions
MockitoAnnotations.initMocks(this);
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
testUser = testPool.getUser(TEST_USER_NAME);
TEST_RESEND_CONFIRM_CODE_RESPONSE = new ResendConfirmationCodeResult();
TEST_RESEND_CONFIRM_CODE_RESPONSE.setCodeDeliveryDetails(new CodeDeliveryDetailsType().withDestination("TestDestination").withDeliveryMedium("TestMedium").withAttributeName("TestAttribute"));
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInCurrentThread.
@Test
public void forgotPasswordInCurrentThread() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
testUser = testPool.getUser(TEST_USER_NAME);
final FlowTracker tracker;
tracker = new FlowTracker("getResetCode");
tracker.activate();
doReturn(TEST_FORGOT_PASSWORD_RESPONSE).when(mockCSIClient).forgotPassword(any(ForgotPasswordRequest.class));
testUser.forgotPassword(new ForgotPasswordHandler() {
public void onSuccess() {
// Check the flow
assertTrue(tracker.check("onSuccess"));
}
public void getResetCode(ForgotPasswordContinuation var1) {
assertTrue(tracker.check("getResetCode"));
tracker.setNext("onSuccess");
doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
var1.setPassword(TEST_USER_PASSWORD);
var1.setVerificationCode(TEST_CODE);
var1.continueTask();
}
public void onFailure(Exception var1) {
assertTrue(tracker.check("onFailure"));
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderForgotPasswordTest method confirmPasswordInCurrentThreadNoCallback.
@Test
public void confirmPasswordInCurrentThreadNoCallback() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
testUser = testPool.getUser(TEST_USER_NAME);
doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
try {
testUser.confirmPassword(TEST_CODE, TEST_USER_PASSWORD, null);
} catch (final CognitoParameterInvalidException exception) {
return;
}
assertTrue("CognitoParameterInvalidException is not thrown when the callback to confirmPassword in null.", true);
}
Aggregations