use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class FieldFinderTest method extractsSerializedModelFieldValue.
/**
* Extracts the field value for a serialized model.
* @throws AmplifyException On failure to derive ModelSchema or to convert Java model to Map
* @throws NoSuchFieldException If field name does not exist for model
*/
@Test
public void extractsSerializedModelFieldValue() throws AmplifyException, NoSuchFieldException {
String username = "foo";
User user = User.builder().username(username).build();
ModelSchema modelSchema = ModelSchema.fromModelClass(User.class);
Map<String, Object> map = ModelConverter.toMap(user, modelSchema);
SerializedModel serializedModel = SerializedModel.builder().serializedData(map).modelSchema(modelSchema).build();
Object extractedValue = FieldFinder.extractFieldValue(serializedModel, "username");
Assert.assertEquals(username, extractedValue);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method arrangeDataEmittingSubscription.
@SuppressWarnings("SameParameterValue")
private static <T extends Model> void arrangeDataEmittingSubscription(AppSync appSync, ModelSchema modelSchema, SubscriptionType subscriptionType, GraphQLResponse<ModelWithMetadata<T>> response) throws DataStoreException {
Answer<Cancelable> answer = invocation -> {
final int startConsumerIndex = 1;
Consumer<String> onStart = invocation.getArgument(startConsumerIndex);
onStart.accept(RandomString.string());
final int dataConsumerIndex = 2;
Consumer<GraphQLResponse<ModelWithMetadata<T>>> onData = invocation.getArgument(dataConsumerIndex);
onData.accept(response);
return new NoOpCancelable();
};
arrangeSubscription(appSync, answer, modelSchema, subscriptionType);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SyncProcessorTest method syncExpressionsAppliedOnSyncRequest.
/**
* Verify that the syncExpressions from the DataStoreConfiguration are applied to the sync request.
* @throws AmplifyException On failure interacting with storage adapter
* @throws InterruptedException If interrupted while awaiting terminal result in test observer
*/
@Test
public void syncExpressionsAppliedOnSyncRequest() throws AmplifyException, InterruptedException {
// Arrange some responses from AppSync
AppSyncMocking.sync(appSync).mockSuccessResponse(Post.class, DELETED_DRUM_POST).mockSuccessResponse(BlogOwner.class, BLOGGER_JAMESON);
// Act: hydrate the local store.
TestObserver<Void> hydrationObserver = syncProcessor.hydrate().test();
// Assert that hydration completed without error.
assertTrue(hydrationObserver.await(OP_TIMEOUT_MS, TimeUnit.MILLISECONDS));
hydrationObserver.assertNoErrors();
hydrationObserver.assertComplete();
// Mock the AppSync interface, and verify that it gets calls with the expected predicate
ModelSchema blogOwnerSchema = ModelSchema.fromModelClass(BlogOwner.class);
verify(appSync, times(1)).buildSyncRequest(blogOwnerSchema, null, 1_000, BlogOwner.NAME.beginsWith("J"));
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SqlCommandTest method queryWithSortBy.
/**
* Validates that a query, with an order by clause is generated correctly.
* @throws DataStoreException From {@link SQLCommandFactory#queryFor(ModelSchema, QueryOptions)}
*/
@Test
public void queryWithSortBy() throws DataStoreException {
final ModelSchema personSchema = getPersonModelSchema();
final SqlCommand sqlCommand = sqlCommandFactory.queryFor(personSchema, Where.matchesAll().sorted(new QuerySortBy("lastName", QuerySortOrder.ASCENDING), new QuerySortBy("firstName", QuerySortOrder.DESCENDING)));
assertNotNull(sqlCommand);
assertEquals(PERSON_BASE_QUERY + " ORDER BY `Person`.`lastName` ASC, `Person`.`firstName` DESC;", sqlCommand.sqlStatement());
assertEquals(0, sqlCommand.getBindings().size());
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SqlCommandTest method validModelSchemaReturnsExpectedSqlCommand.
/**
* Test if a valid {@link ModelSchema} returns an expected
* CREATE TABLE SQL command.
*/
@Test
public void validModelSchemaReturnsExpectedSqlCommand() {
final ModelSchema personSchema = getPersonModelSchema();
final SqlCommand sqlCommand = sqlCommandFactory.createTableFor(personSchema);
assertEquals("Person", sqlCommand.tableName());
assertEquals("CREATE TABLE IF NOT EXISTS `Person` (" + "`id` TEXT PRIMARY KEY NOT NULL, " + "`age` INTEGER, " + "`firstName` TEXT NOT NULL, " + "`lastName` TEXT NOT NULL);", sqlCommand.sqlStatement());
}
Aggregations