Search in sources :

Example 1 with LoginIdentity

use of com.fitpay.android.api.models.user.LoginIdentity in project fitpay-android-sdk by fitpay.

the class UserTest2 method testCantLoginWithDifferentPassword.

@Test
// this test does not work in demo environment since does auto-login
@Ignore
public void testCantLoginWithDifferentPassword() throws Exception {
    this.user = getUser();
    assertNotNull(user);
    LoginIdentity badCredentials = getTestLoginIdentity(userName, TestUtils.getRandomLengthNumber(4, 4));
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<OAuthToken> callback = new ResultProvidingCallback<>(latch);
    ApiManager.getInstance().loginUser(badCredentials, callback);
    boolean completed = latch.await(TIMEOUT, TimeUnit.SECONDS);
    assertTrue("login did not complete successfully", completed);
    assertEquals("login error code. (message: " + callback.getErrorMessage() + ")", 401, callback.getErrorCode());
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) CountDownLatch(java.util.concurrent.CountDownLatch) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with LoginIdentity

use of com.fitpay.android.api.models.user.LoginIdentity in project fitpay-android-sdk by fitpay.

the class Steps method login.

public void login() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    LoginIdentity loginIdentity = null;
    try {
        loginIdentity = new LoginIdentity.Builder().setUsername(userName).setPassword(password).build();
    } catch (ValidationException ignored) {
    }
    Assert.assertNotNull(loginIdentity);
    ApiManager.getInstance().loginUser(loginIdentity, new ApiCallback<OAuthToken>() {

        @Override
        public void onSuccess(OAuthToken result) {
            Assert.assertNotNull("missing bearer token", result.getAccessToken());
            isRequestSuccess[0] = true;
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            fail("unable to login: " + errorMessage);
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    Assert.assertTrue(isRequestSuccess[0]);
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) ValidationException(com.fitpay.android.utils.ValidationException) CountDownLatch(java.util.concurrent.CountDownLatch) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity)

Aggregations

OAuthToken (com.fitpay.android.api.models.security.OAuthToken)2 LoginIdentity (com.fitpay.android.api.models.user.LoginIdentity)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ResultProvidingCallback (com.fitpay.android.api.callbacks.ResultProvidingCallback)1 ValidationException (com.fitpay.android.utils.ValidationException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1