use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method ownerFieldIsRemovedIfNull.
/**
* Verify that the owner field is removed if the value is null.
* @throws AmplifyException On failure to build schema
*/
@Test
public void ownerFieldIsRemovedIfNull() throws AmplifyException {
// Expect
Map<String, Object> expected = new HashMap<>();
expected.put("id", "111");
expected.put("description", "Mop the floor");
expected.put("_version", 1);
// Act
Todo todo = new Todo("111", "Mop the floor", null);
ModelSchema schema = ModelSchema.fromModelClass(Todo.class);
@SuppressWarnings("unchecked") Map<String, Object> actual = (Map<String, Object>) AppSyncRequestFactory.buildUpdateRequest(schema, todo, 1, QueryPredicates.all(), DEFAULT_STRATEGY).getVariables().get("input");
// Assert
assertEquals(expected, actual);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateMutationGenerationOnCreateNestedCustomType.
/**
* Validates creation of a "create a model" request for nested custom type.
* @throws AmplifyException On failure to interrogate the model fields.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validateMutationGenerationOnCreateNestedCustomType() throws AmplifyException, JSONException {
ModelSchema schema = ModelSchema.fromModelClass(Parent.class);
JSONAssert.assertEquals(Resources.readAsString("create-parent-request.txt"), AppSyncRequestFactory.buildCreationRequest(schema, buildTestParentModel(), DEFAULT_STRATEGY).getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateDeleteWithCustomPrimaryKey.
/**
* Checks that we're getting the expected output for a delete mutation for an object with a custom primary key.
* @throws DataStoreException If the output does not match.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validateDeleteWithCustomPrimaryKey() throws AmplifyException, JSONException {
ModelSchema schema = ModelSchema.fromModelClass(Item.class);
final Item item = Item.builder().orderId("123a7asa").status(Status.IN_TRANSIT).createdAt(new Temporal.DateTime("2021-04-20T15:20:32.651Z")).name("Gummy Bears").build();
JSONAssert.assertEquals(Resources.readAsString("delete-item.txt"), AppSyncRequestFactory.buildDeletionRequest(schema, item, 1, QueryPredicates.all(), DEFAULT_STRATEGY).getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateRequestGenerationForPagination.
/**
* Validates that the nextToken parameter is correctly generate for a Sync query.
* @throws DataStoreException On failure to interrogate the BlogOwner.class.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validateRequestGenerationForPagination() throws AmplifyException, JSONException {
Integer limit = 1000;
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
final GraphQLRequest<Iterable<Post>> request = AppSyncRequestFactory.buildSyncRequest(schema, null, limit, QueryPredicates.all(), DEFAULT_STRATEGY);
JSONAssert.assertEquals(Resources.readAsString("base-sync-request-paginating-blog-owners.txt"), request.getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateRequestGenerationForBaseSync.
/**
* Validates the construction of a base-sync query document.
* @throws DataStoreException On failure to interrogate fields in Blog.class
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals
*/
@Test
public void validateRequestGenerationForBaseSync() throws AmplifyException, JSONException {
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
JSONAssert.assertEquals(Resources.readAsString("base-sync-request-document-for-blog-owner.txt"), AppSyncRequestFactory.buildSyncRequest(schema, null, null, QueryPredicates.all(), DEFAULT_STRATEGY).getContent(), true);
}
Aggregations