use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SqlCommandTest method queryWithCustomPaginationInput.
/**
* Verifies that the correct SQL bindings are generated when specifying the
* {@link Page#startingAt(int)} and {@link QueryPaginationInput#withLimit(Integer)}
* page details.
* @throws DataStoreException From {@link SQLCommandFactory#queryFor(ModelSchema, QueryOptions)}
*/
@Test
public void queryWithCustomPaginationInput() throws DataStoreException {
final ModelSchema personSchema = getPersonModelSchema();
final SqlCommand sqlCommand = sqlCommandFactory.queryFor(personSchema, Where.matchesAll().paginated(Page.startingAt(2).withLimit(20)));
assertNotNull(sqlCommand);
assertEquals(PERSON_BASE_QUERY + " LIMIT ? OFFSET ?;", sqlCommand.sqlStatement());
final List<Object> bindings = sqlCommand.getBindings();
assertEquals(2, bindings.size());
assertEquals(20, bindings.get(0));
assertEquals(40, bindings.get(1));
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SqlCommandTest method queryWithFirstPagePaginationInput.
/**
* Validates that the correct SQL bindings are created when using the
* {@link Page#firstPage()} query option.
* @throws DataStoreException From {@link SQLCommandFactory#queryFor(ModelSchema, QueryOptions)}
*/
@Test
public void queryWithFirstPagePaginationInput() throws DataStoreException {
final ModelSchema personSchema = getPersonModelSchema();
final SqlCommand sqlCommand = sqlCommandFactory.queryFor(personSchema, Where.matchesAll().paginated(Page.firstPage()));
assertNotNull(sqlCommand);
assertEquals(PERSON_BASE_QUERY + " LIMIT ? OFFSET ?;", sqlCommand.sqlStatement());
final List<Object> bindings = sqlCommand.getBindings();
assertEquals(2, bindings.size());
assertEquals(100, bindings.get(0));
assertEquals(0, bindings.get(1));
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class SQLiteTableTest method createSQLiteTableForPost.
/**
* Test if a {@link ModelSchema} for {@link Post} returns an expected {@link SQLiteTable}. This tests the general
* use case, for an object with most data types (String, Integer, enum, BelongsTo, and HasMany relationships).
* @throws AmplifyException on error deriving ModelSchema.
*/
@Test
public void createSQLiteTableForPost() throws AmplifyException {
ModelSchema schema = ModelSchema.fromModelClass(Post.class);
Map<String, SQLiteColumn> columns = new HashMap<>();
columns.put("id", SQLiteColumn.builder().name("id").fieldName("id").dataType(SQLiteDataType.TEXT).isNonNull(true).tableName("Post").build());
columns.put("title", SQLiteColumn.builder().name("title").fieldName("title").dataType(SQLiteDataType.TEXT).isNonNull(true).tableName("Post").build());
columns.put("blog", SQLiteColumn.builder().name("postBlogId").fieldName("blog").dataType(SQLiteDataType.TEXT).isNonNull(false).tableName("Post").ownerOf("Blog").build());
columns.put("status", SQLiteColumn.builder().name("status").fieldName("status").dataType(SQLiteDataType.TEXT).isNonNull(true).tableName("Post").build());
columns.put("rating", SQLiteColumn.builder().name("rating").fieldName("rating").dataType(SQLiteDataType.INTEGER).isNonNull(true).tableName("Post").build());
columns.put("createdAt", SQLiteColumn.builder().name("createdAt").fieldName("createdAt").dataType(SQLiteDataType.TEXT).isNonNull(false).tableName("Post").build());
SQLiteTable expected = SQLiteTable.builder().columns(columns).name("Post").build();
SQLiteTable actual = SQLiteTable.fromSchema(schema);
assertEquals(expected, actual);
assertEquals("id", actual.getPrimaryKey().getFieldName());
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class GsonPendingMutationConverterTest method convertPendingMutationToRecordAndBack.
/**
* Validate that the {@link GsonPendingMutationConverter} can be
* used to convert a sample {@link PendingMutation} to a
* {@link PendingMutation.PersistentRecord}, and vice-versa.
* @throws DataStoreException from DataStore conversion
* @throws AmplifyException On failure to arrange model schema
*/
@Test
public void convertPendingMutationToRecordAndBack() throws AmplifyException {
// Arrange a PendingMutation<Blog>
Blog blog = Blog.builder().name("A neat blog").owner(BlogOwner.builder().name("Joe Swanson").build()).build();
ModelSchema schema = ModelSchema.fromModelClass(Blog.class);
PendingMutation<Blog> originalMutation = PendingMutation.creation(blog, schema);
String expectedMutationId = originalMutation.getMutationId().toString();
// Instantiate the object under test
PendingMutation.Converter converter = new GsonPendingMutationConverter();
// Try to construct a record from the PendingMutation instance.
PendingMutation.PersistentRecord record = converter.toRecord(originalMutation);
assertNotNull(record);
assertEquals(expectedMutationId, record.getId());
// Now, try to convert it back...
PendingMutation<Blog> reconstructedItemChange = converter.fromRecord(record);
assertEquals(originalMutation, reconstructedItemChange);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class GsonPendingMutationConverterTest method convertPendingMutationWithSerializedModelToRecordAndBack.
/**
* Validate that the {@link GsonPendingMutationConverter} can be
* used to convert a sample {@link PendingMutation} to a
* {@link PendingMutation.PersistentRecord}, and vice-versa.
* @throws DataStoreException from DataStore conversion
* @throws AmplifyException On failure to arrange model schema
*/
@Test
public void convertPendingMutationWithSerializedModelToRecordAndBack() throws AmplifyException {
// Arrange a PendingMutation<SerializedModel>
BlogOwner blogOwner = BlogOwner.builder().name("Joe Swanson").build();
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
SerializedModel serializedBlogOwner = SerializedModel.create(blogOwner, schema);
PendingMutation<SerializedModel> originalMutation = PendingMutation.creation(serializedBlogOwner, schema);
String expectedMutationId = originalMutation.getMutationId().toString();
// Instantiate the object under test
PendingMutation.Converter converter = new GsonPendingMutationConverter();
// Try to construct a record from the PendingMutation instance.
PendingMutation.PersistentRecord record = converter.toRecord(originalMutation);
assertNotNull(record);
assertEquals(expectedMutationId, record.getId());
// Now, try to convert it back...
PendingMutation<SerializedModel> reconstructedItemChange = converter.fromRecord(record);
assertEquals(originalMutation, reconstructedItemChange);
}
Aggregations