Search in sources :

Example 6 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testDeleteUser.

/**
 * Tests that a successful request to delete the currently signed in user will
 * propagate a completion back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testDeleteUser() throws InterruptedException {
    // Arrange an invocation of the success Action
    doAnswer(invocation -> {
        // 0 = onComplete, 1 = onFailure
        Action onCompletion = invocation.getArgument(0);
        onCompletion.call();
        return null;
    }).when(delegate).deleteUser(anyAction(), anyConsumer());
    // Act: call the binding
    TestObserver<Void> observer = auth.deleteUser().test();
    // Assert: Completable completes with success
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) Test(org.junit.Test)

Example 7 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignOutSucceeds.

/**
 * Validates that a successful sign-out will propagate up into the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignOutSucceeds() throws InterruptedException {
    // Arrange an invocation of the success action
    doAnswer(invocation -> {
        // 0 = onComplete, 1 = onFailure
        int positionOfCompletionAction = 0;
        Action onComplete = invocation.getArgument(positionOfCompletionAction);
        onComplete.call();
        return null;
    }).when(delegate).signOut(anyAction(), anyConsumer());
    // Act: call the binding
    TestObserver<Void> observer = auth.signOut().test();
    // Assert: Completable completes successfully
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) Test(org.junit.Test)

Example 8 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testForgetSpecificDevice.

/**
 * Tests that a successful request to forget a specific auth device will propagate a completion
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testForgetSpecificDevice() throws InterruptedException {
    // Arrange an invocation of the success Action
    doAnswer(invocation -> {
        // 0 = deviceToForget, 1 = onComplete, 2 = onFailure
        Action onCompletion = invocation.getArgument(1);
        onCompletion.call();
        return null;
    }).when(delegate).forgetDevice(any(), anyAction(), anyConsumer());
    // Act: call the binding
    AuthDevice deviceToForget = AuthDevice.fromId(RandomString.string());
    TestObserver<Void> observer = auth.forgetDevice(deviceToForget).test();
    // Assert: Completable completes with success
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) AuthDevice(com.amplifyframework.auth.AuthDevice) Test(org.junit.Test)

Example 9 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testForgetCurrentDevice.

/**
 * Tests that a successful request to forget current auth device will propagate a completion
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testForgetCurrentDevice() throws InterruptedException {
    // Arrange an invocation of the success Action
    doAnswer(invocation -> {
        // 0 = onComplete, 1 = onFailure
        Action onCompletion = invocation.getArgument(0);
        onCompletion.call();
        return null;
    }).when(delegate).forgetDevice(anyAction(), anyConsumer());
    // Act: call the binding
    TestObserver<Void> observer = auth.forgetDevice().test();
    // Assert: Completable completes with success
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) Test(org.junit.Test)

Example 10 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxDataStoreBindingTest method observeCompletesWhenCategoryBehaviorDoes.

/**
 * The Rx binding for the DataStore's observe method is an Observable. It should
 * complete when the Rx binding's completion callback is triggered.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void observeCompletesWhenCategoryBehaviorDoes() throws InterruptedException {
    // Category behavior is arranged to complete
    doAnswer(invocation -> {
        // 0 = clazz, 1 = onStart, 2 = onNext, 3 = onFailure, 4 = onComplete
        final int positionOfOnStart = 2;
        Consumer<Cancelable> onStart = invocation.getArgument(positionOfOnStart);
        onStart.accept(new NoOpCancelable());
        final int positionOfOnComplete = 4;
        Action onComplete = invocation.getArgument(positionOfOnComplete);
        onComplete.call();
        // "void"
        return null;
    }).when(delegate).observe(eq(Model.class), anyConsumer(), anyConsumer(), anyConsumer(), anyAction());
    // Act: observe via Rx binding
    TestObserver<DataStoreItemChange<Model>> observer = rxDataStore.observe(Model.class).test();
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertComplete();
    verify(delegate).observe(eq(Model.class), anyConsumer(), anyConsumer(), anyConsumer(), anyAction());
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) DataStoreItemChange(com.amplifyframework.datastore.DataStoreItemChange) RandomModel(com.amplifyframework.testutils.random.RandomModel) Model(com.amplifyframework.core.model.Model) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) Cancelable(com.amplifyframework.core.async.Cancelable) Test(org.junit.Test)

Aggregations

Action (com.amplifyframework.core.Action)36 Test (org.junit.Test)34 Cancelable (com.amplifyframework.core.async.Cancelable)23 Consumer (com.amplifyframework.core.Consumer)21 DataStoreException (com.amplifyframework.datastore.DataStoreException)21 ObserveQueryOptions (com.amplifyframework.core.model.query.ObserveQueryOptions)20 DataStoreQuerySnapshot (com.amplifyframework.datastore.DataStoreQuerySnapshot)20 Arrays (java.util.Arrays)20 List (java.util.List)20 TimeUnit (java.util.concurrent.TimeUnit)20 NoOpAction (com.amplifyframework.core.NoOpAction)19 NoOpConsumer (com.amplifyframework.core.NoOpConsumer)19 QuerySortBy (com.amplifyframework.core.model.query.QuerySortBy)19 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)19 Post (com.amplifyframework.testmodels.commentsblog.Post)19 PostStatus (com.amplifyframework.testmodels.commentsblog.PostStatus)19 ArrayList (java.util.ArrayList)19 Collections (java.util.Collections)19 Comparator (java.util.Comparator)19 CountDownLatch (java.util.concurrent.CountDownLatch)19