use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class GraphQLInstrumentationTest method setUp.
/**
* Configure the Amplify framework, if that hasn't already happened in this process instance.
* @throws AmplifyException From Amplify configuration
* @throws SynchronousMobileClient.MobileClientException From failure to initialize auth
*/
@Before
public void setUp() throws AmplifyException, SynchronousMobileClient.MobileClientException {
// Set up and configure API category
ApiCategory asyncDelegate = TestApiCategory.fromConfiguration(R.raw.amplifyconfiguration);
api = SynchronousApi.delegatingTo(asyncDelegate);
// Set up Auth
mobileClient = SynchronousMobileClient.instance();
mobileClient.initialize();
mobileClient.signOut();
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class AWSDataStorePluginTest method startInLocalMode.
/**
* Starting the plugin in local mode (no API plugin) works without freezing or crashing the calling thread.
* @throws AmplifyException Not expected; on failure to configure of initialize plugin.
*/
@Test
public void startInLocalMode() throws AmplifyException {
// Configure DataStore with an empty config (All defaults)
HubAccumulator dataStoreReadyObserver = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.READY, 1).start();
ApiCategory emptyApiCategory = spy(ApiCategory.class);
AWSDataStorePlugin standAloneDataStorePlugin = AWSDataStorePlugin.builder().modelProvider(modelProvider).apiCategory(emptyApiCategory).build();
SynchronousDataStore synchronousDataStore = SynchronousDataStore.delegatingTo(standAloneDataStorePlugin);
standAloneDataStorePlugin.configure(new JSONObject(), context);
standAloneDataStorePlugin.initialize(context);
// Trick the DataStore since it's not getting initialized as part of the Amplify.initialize call chain
Amplify.Hub.publish(HubChannel.DATASTORE, HubEvent.create(InitializationStatus.SUCCEEDED));
synchronousDataStore.start();
dataStoreReadyObserver.await();
assertSyncProcessorNotStarted(emptyApiCategory);
Person person1 = createPerson("Test", "Dummy I");
synchronousDataStore.save(person1);
assertNotNull(person1.getId());
Person person1FromDb = synchronousDataStore.get(Person.class, person1.getId());
assertEquals(person1, person1FromDb);
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class AWSDataStorePluginTest method startInApiMode.
/**
* Starting the plugin when in API sync mode succeeds without freezing or crashing the calling thread.
* @throws JSONException on failure to arrange plugin config
* @throws AmplifyException on failure to arrange API plugin via Amplify facade
*/
@Test
public void startInApiMode() throws JSONException, AmplifyException {
HubAccumulator dataStoreReadyObserver = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.READY, 1).start();
HubAccumulator subscriptionsEstablishedObserver = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.SUBSCRIPTIONS_ESTABLISHED, 1).start();
HubAccumulator networkStatusObserver = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.NETWORK_STATUS, 1).start();
ApiCategory mockApiCategory = mockApiCategoryWithGraphQlApi();
JSONObject dataStorePluginJson = new JSONObject().put("syncIntervalInMinutes", 60);
AWSDataStorePlugin awsDataStorePlugin = AWSDataStorePlugin.builder().modelProvider(modelProvider).apiCategory(mockApiCategory).build();
SynchronousDataStore synchronousDataStore = SynchronousDataStore.delegatingTo(awsDataStorePlugin);
awsDataStorePlugin.configure(dataStorePluginJson, context);
awsDataStorePlugin.initialize(context);
// Trick the DataStore since it's not getting initialized as part of the Amplify.initialize call chain
Amplify.Hub.publish(HubChannel.DATASTORE, HubEvent.create(InitializationStatus.SUCCEEDED));
synchronousDataStore.start();
dataStoreReadyObserver.await();
subscriptionsEstablishedObserver.await();
networkStatusObserver.await();
assertRemoteSubscriptionsStarted();
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class AWSDataStorePluginTest method configureAndInitialize.
/**
* Configuring and initializing the plugin succeeds without freezing or crashing the calling thread. Basic. 🙄
* @throws AmplifyException On failure to configure or initialize plugin.
*/
@Test
public void configureAndInitialize() throws AmplifyException {
// Configure DataStore with an empty config (All defaults)
ApiCategory emptyApiCategory = spy(ApiCategory.class);
AWSDataStorePlugin standAloneDataStorePlugin = AWSDataStorePlugin.builder().modelProvider(modelProvider).apiCategory(emptyApiCategory).build();
standAloneDataStorePlugin.configure(new JSONObject(), context);
standAloneDataStorePlugin.initialize(context);
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class ConflictResolverIntegrationTest method conflictIsResolvedByRetryingLocalData.
/**
* When {@link Completable} completes,
* then the local storage adapter should have all of the remote model state.
* @throws AmplifyException On failure interacting with storage adapter
* @throws InterruptedException If interrupted while awaiting terminal result in test observer
* @throws JSONException If unable to parse the JSON.
*/
// Varied types in Observable.fromArray(...).
@SuppressWarnings("unchecked")
@Test
public void conflictIsResolvedByRetryingLocalData() throws AmplifyException, JSONException, InterruptedException {
CountDownLatch latch = new CountDownLatch(4);
// Arrange for the user-provided conflict handler to always request local retry.
ApiCategory mockApiCategory = mockApiCategoryWithGraphQlApi();
Person person1 = setupApiMock(latch, mockApiCategory);
JSONObject dataStorePluginJson = new JSONObject().put("syncIntervalInMinutes", 60);
AWSDataStorePlugin awsDataStorePlugin = AWSDataStorePlugin.builder().modelProvider(modelProvider).apiCategory(mockApiCategory).dataStoreConfiguration(DataStoreConfiguration.builder().conflictHandler(DataStoreConflictHandler.alwaysRetryLocal()).build()).build();
SynchronousDataStore synchronousDataStore = SynchronousDataStore.delegatingTo(awsDataStorePlugin);
awsDataStorePlugin.configure(dataStorePluginJson, context);
awsDataStorePlugin.initialize(context);
awsDataStorePlugin.start(() -> {
}, (onError) -> {
});
// Trick the DataStore since it's not getting initialized as part of the Amplify.initialize call chain
Amplify.Hub.publish(HubChannel.DATASTORE, HubEvent.create(InitializationStatus.SUCCEEDED));
// Save person 1
synchronousDataStore.save(person1);
Person result1 = synchronousDataStore.get(Person.class, person1.getId());
assertTrue(latch.await(2, TimeUnit.SECONDS));
assertEquals(person1, result1);
}
Aggregations