use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpResourceNotFoundException.
// Register with invalid clientId
@Test
public void signUpResourceNotFoundException() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
ResourceNotFoundException exception = new ResourceNotFoundException("registration failed");
doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
testPool.signUp(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 ResourceNotFoundException);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpPasswordException.
// Register with invalid password
@Test
public void signUpPasswordException() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
InvalidParameterException exception = new InvalidParameterException("registration failed");
doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
testPool.signUp(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);
assertNotNull(signUpResult.getUserConfirmed());
assertEquals(TEST_USER_NAME, user.getUserId());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
assertTrue(exception instanceof InvalidParameterException);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserInCurrentThread.
@Test
public void signUpUserInCurrentThread() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNull(requestSent.getValidationData());
// Verify results
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserWithoutPPInCurrentThread.
@Test
public void signUpUserWithoutPPInCurrentThread() throws Exception {
// Test shared Pinpoint context
awsKeyValueStorageUtility.put(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1);
// Test new user pool creation with PP app id.
CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNull(requestSent.getValidationData());
assertNull(requestSent.getAnalyticsMetadata());
// Verify results
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserWithPPInCurrentThread.
@Test
public void signUpUserWithPPInCurrentThread() throws Exception {
// Test shared Pinpoint context
ApplicationProvider.getApplicationContext().getSharedPreferences(TEST_PP_APP_ID_1 + PP_PREFERENCES_AND_FILE_MANAGER_SUFFIX, Context.MODE_PRIVATE).edit().putString(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1).apply();
// Test new user pool creation with PP app id.
CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient, TEST_PP_APP_ID_1);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNull(requestSent.getValidationData());
assertNotNull(requestSent.getAnalyticsMetadata());
assertEquals(TEST_PP_ENDPOINT_1, requestSent.getAnalyticsMetadata().getAnalyticsEndpointId());
// Verify results
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
Aggregations