use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceTest method testGetUserName.
@Test
public void testGetUserName() {
signInAndVerifySignIn();
assertNotNull(auth.getUsername());
deleteAllEncryptionKeys();
assertNull(auth.getUsername());
try {
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertNotNull(signInResult);
assertEquals(SignInState.DONE, signInResult.getSignInState());
} catch (Exception ex) {
fail(ex.getMessage());
}
assertNotNull(auth.getUsername());
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceTest method testGetIdentityId.
@Test
public void testGetIdentityId() {
signInAndVerifySignIn();
String identityId = auth.getIdentityId();
assertNotNull(identityId);
deleteAllEncryptionKeys();
assertNull(auth.getIdentityId());
try {
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertNotNull(signInResult);
assertEquals(SignInState.DONE, signInResult.getSignInState());
} catch (Exception ex) {
fail(ex.getMessage());
}
String identityIdAfterSecondSignIn = auth.getIdentityId();
assertNotNull(identityIdAfterSecondSignIn);
assertEquals(identityId, identityIdAfterSecondSignIn);
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceTest method testGetUserAttributes.
@Test
public void testGetUserAttributes() throws Exception {
signInAndVerifySignIn();
Map<String, String> userAttributes = auth.getUserAttributes();
assertNotNull(userAttributes);
assertEquals(getPackageConfigure().getString("email"), userAttributes.get("email"));
deleteAllEncryptionKeys();
try {
auth.getUserAttributes();
} catch (Exception ex) {
assertEquals("Operation requires a signed-in state", ex.getMessage());
}
try {
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertNotNull(signInResult);
assertEquals(SignInState.DONE, signInResult.getSignInState());
} catch (Exception ex) {
fail(ex.getMessage());
}
userAttributes = auth.getUserAttributes();
assertNotNull(userAttributes);
assertEquals(getPackageConfigure().getString("email"), userAttributes.get("email"));
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceTest method testGetTokens.
// When the encryption keys are lost and retrieval of
// tokens from persistent store fails, calling getTokens()
// will throw an exception and the UserStateListener will
// be triggered the userState as SIGNED_OUT. Followed by a
// SignIn operation, getTokens() will retrieve
// the tokens successfully and trigger the userState as
// SIGNED_IN.
@Test
public void testGetTokens() throws Exception {
signInAndVerifySignIn();
final CountDownLatch stateNotificationLatch = new CountDownLatch(1);
final AtomicReference<UserStateDetails> userState = new AtomicReference<UserStateDetails>();
listener = new UserStateListener() {
@Override
public void onUserStateChanged(UserStateDetails details) {
userState.set(details);
stateNotificationLatch.countDown();
}
};
auth.addUserStateListener(listener);
deleteAllEncryptionKeys();
try {
auth.getTokens();
} catch (Exception ex) {
assertEquals("getTokens does not support retrieving tokens while signed-out", ex.getMessage());
}
stateNotificationLatch.await(10, TimeUnit.SECONDS);
assertEquals(UserState.SIGNED_OUT, userState.get().getUserState());
try {
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertNotNull(signInResult);
assertEquals(SignInState.DONE, signInResult.getSignInState());
} catch (Exception ex) {
fail(ex.getMessage());
}
Tokens tokens = auth.getTokens();
verifyTokens(tokens);
assertEquals(UserState.SIGNED_IN, userState.get().getUserState());
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceWithRestartabilityTest method testIsSignedIn.
@Test
public void testIsSignedIn() {
signInAndVerifySignIn();
assertTrue(auth.isSignedIn());
deleteAllEncryptionKeys();
initializeAWSMobileClient(appContext, UserState.SIGNED_OUT);
assertFalse(auth.isSignedIn());
try {
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertNotNull(signInResult);
assertEquals(SignInState.DONE, signInResult.getSignInState());
} catch (Exception ex) {
fail(ex.getMessage());
}
assertTrue(auth.isSignedIn());
}
Aggregations