use of com.okta.oidc.AuthenticationResultHandler.ResultType in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignInCanceled.
@Test
public void onActivityResultSignInCanceled() throws InterruptedException {
Intent intent = new Intent();
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_CANCELED, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), CANCELED);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.ResultType in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignOutSuccess.
@Test
public void onActivityResultSignOutSuccess() throws InterruptedException {
Intent intent = new Intent();
intent.setData(Uri.parse("com.okta.test:/logout?state=" + CUSTOM_STATE));
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_OUT, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
LogoutResponse response = (LogoutResponse) stateResult[0].getAuthorizationResponse();
assertNotNull(response);
assertEquals(stateResult[0].getStatus(), LOGGED_OUT);
assertEquals(response.getState(), CUSTOM_STATE);
assertEquals(stateType[0], ResultType.SIGN_OUT);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.ResultType in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignOutCanceled.
@Test
public void onActivityResultSignOutCanceled() throws InterruptedException {
Intent intent = new Intent();
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_OUT, RESULT_CANCELED, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), CANCELED);
assertEquals(stateType[0], ResultType.SIGN_OUT);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.ResultType in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method setAuthenticationListener.
@Test
public void setAuthenticationListener() throws InterruptedException {
AuthenticationResultHandler.handler().mCachedResult = StateResult.canceled();
AuthenticationResultHandler.handler().mCachedResultType = ResultType.SIGN_IN;
final StateResult[] resultFromListener = new StateResult[1];
final ResultType[] typeFromListener = new ResultType[1];
CountDownLatch latch = new CountDownLatch(1);
AuthResultListener listener = (result, type) -> {
resultFromListener[0] = result;
typeFromListener[0] = type;
latch.countDown();
};
AuthenticationResultHandler.handler().setAuthenticationListener(listener);
latch.await();
assertEquals(resultFromListener[0].getStatus(), CANCELED);
assertEquals(typeFromListener[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.ResultType in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignOutFailed.
@Test
public void onActivityResultSignOutFailed() throws InterruptedException {
Intent intent = new Intent();
intent.setData(Uri.parse("com.okta.test:/authorize?error=" + TestValues.ERROR));
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_OUT, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().error, TestValues.ERROR);
assertEquals(stateType[0], ResultType.SIGN_OUT);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
Aggregations