Search in sources :

Example 1 with UserCreateRequest

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

the class WebViewCommunicatorTest method setup.

@Before
public void setup() throws Exception {
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest user = getNewTestUser(userName, pin);
    User createdUser = createUser(user);
    assertNotNull("user should have been created", createdUser);
    loginIdentity = getTestLoginIdentity(userName, pin);
    doLogin(loginIdentity);
    this.user = getUser();
    assertNotNull(user);
    Device device = getTestDevice();
    Device createdDevice = createDevice(this.user, device);
    assertNotNull("device", createdDevice);
}
Also used : User(com.fitpay.android.api.models.user.User) Device(com.fitpay.android.api.models.device.Device) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Before(org.junit.Before)

Example 2 with UserCreateRequest

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

the class UserServiceTest method canCreateUser.

@Test
public void canCreateUser() throws Exception {
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest user = getNewTestUser(userName, pin);
    User createdUser = createUser(user);
    assertNotNull("user should have been created", createdUser);
}
Also used : User(com.fitpay.android.api.models.user.User) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Test(org.junit.Test)

Example 3 with UserCreateRequest

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

the class UserServiceTest method canCreateFullyDefinedUser.

@Test
public void canCreateFullyDefinedUser() throws Exception {
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest user = new UserCreateRequest.Builder().email(userName).pin(pin).birthDate("2015-09-15").firstName(TestUtils.getRandomLengthString(5, 10)).lastName(TestUtils.getRandomLengthString(5, 10)).origin("fitpay").originAccountCreatedAtEpoch(new Date().getTime()).termsVersion("01").termsAcceptedAtEpoch(new Date().getTime()).build();
    User createdUser = createUser(user);
    assertNotNull("user should have been created", createdUser);
}
Also used : User(com.fitpay.android.api.models.user.User) Date(java.util.Date) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Test(org.junit.Test)

Example 4 with UserCreateRequest

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

the class Steps method createUser.

public User createUser() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    UserCreateRequest ucr = new UserCreateRequest.Builder().email(userName).pin(password).build();
    ApiManager.getInstance().createUser(ucr, new ApiCallback<User>() {

        @Override
        public void onSuccess(User result) {
            currentUser = result;
            resetErrorFields();
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            currentErrorCode = errorCode;
            currentErrorMessage = errorMessage;
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    Assert.assertNotNull(currentUser);
    Assert.assertNotNull(currentUser.getUsername());
    return currentUser;
}
Also used : User(com.fitpay.android.api.models.user.User) CountDownLatch(java.util.concurrent.CountDownLatch) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest)

Example 5 with UserCreateRequest

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

the class DeviceSyncManagerTest method testActionsSetup.

@Before
@Override
public void testActionsSetup() throws Exception {
    SharedPreferences sp = Mockito.mock(SharedPreferences.class);
    Mockito.when(sp.getAll()).thenReturn(Collections.emptyMap());
    Mockito.when(sp.getString(Matchers.eq("lastCommitId"), (String) Matchers.isNull())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return lastCommitId;
        }
    });
    SharedPreferences.Editor spEditor = Mockito.mock(SharedPreferences.Editor.class);
    Mockito.when(sp.edit()).thenReturn(spEditor);
    Mockito.when(spEditor.putString(Matchers.eq("lastCommitId"), Matchers.anyString())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            lastCommitId = (String) invocation.getArguments()[1];
            return spEditor;
        }
    });
    Mockito.when(spEditor.commit()).thenReturn(true);
    mContext = Mockito.mock(Context.class);
    Mockito.when(mContext.getSharedPreferences(Matchers.anyString(), Matchers.eq(Context.MODE_PRIVATE))).thenReturn(sp);
    syncManager = new DeviceSyncManager(mContext);
    syncManager.onCreate();
    syncManagerCallback = new DeviceSyncManager.DeviceSyncManagerCallback() {

        @Override
        public void syncRequestAdded(SyncRequest request) {
        }

        @Override
        public void syncTaskStarting(SyncRequest request) {
        }

        @Override
        public void syncTaskStarted(SyncRequest request) {
        }

        @Override
        public void syncTaskCompleted(SyncRequest request) {
            if (executionLatch != null) {
                executionLatch.countDown();
            }
        }
    };
    syncManager.registerDeviceSyncManagerCallback(syncManagerCallback);
    mockPaymentDevice = new MockPaymentDeviceConnector();
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest userCreateRequest = getNewTestUser(userName, pin);
    createUser(userCreateRequest);
    assertTrue(doLogin(new LoginIdentity.Builder().setPassword(pin).setUsername(userName).build()));
    this.user = getUser();
    this.device = createDevice(this.user, getTestDevice());
    assertNotNull(this.device);
    String pan = "9999504454545450";
    CreditCard creditCard = getTestCreditCard(pan);
    CreditCard createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    Properties props = new Properties();
    props.put(MockPaymentDeviceConnector.CONFIG_CONNECTED_RESPONSE_TIME, "0");
    mockPaymentDevice.init(props);
    assertEquals("payment service is not initialized", States.INITIALIZED, mockPaymentDevice.getState());
    mockPaymentDevice.connect();
    int count = 0;
    while (mockPaymentDevice.getState() != States.CONNECTED || ++count < 5) {
        Thread.sleep(500);
    }
    assertEquals("payment service should be connected", States.CONNECTED, mockPaymentDevice.getState());
    this.executionLatch = new CountDownLatch(1);
    this.listener = new SyncCompleteListener();
    NotificationManager.getInstance().addListenerToCurrentThread(this.listener);
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) MockPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard) SyncRequest(com.fitpay.android.paymentdevice.models.SyncRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity) DeviceSyncManager(com.fitpay.android.paymentdevice.DeviceSyncManager) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Before(org.junit.Before)

Aggregations

UserCreateRequest (com.fitpay.android.api.models.user.UserCreateRequest)5 User (com.fitpay.android.api.models.user.User)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 CreditCard (com.fitpay.android.api.models.card.CreditCard)1 Device (com.fitpay.android.api.models.device.Device)1 LoginIdentity (com.fitpay.android.api.models.user.LoginIdentity)1 DeviceSyncManager (com.fitpay.android.paymentdevice.DeviceSyncManager)1 MockPaymentDeviceConnector (com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector)1 SyncRequest (com.fitpay.android.paymentdevice.models.SyncRequest)1 Date (java.util.Date)1 Properties (java.util.Properties)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1