use of com.amplifyframework.testmodels.ecommerce.Item in project amplify-android by aws-amplify.
the class AppSyncClientTest method validateDeleteMutationWithCustomPrimaryKey.
/**
* Validates delete mutation for item with custom primary key.
* @throws JSONException from JSONAssert.assertEquals JSON parsing error
* @throws AmplifyException from ModelSchema.fromModelClass to convert model to schema
*/
@Test
public void validateDeleteMutationWithCustomPrimaryKey() throws AmplifyException, JSONException {
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();
ModelSchema schema = ModelSchema.fromModelClass(Item.class);
endpoint.delete(item, schema, 1, response -> {
}, error -> {
});
// Now, capture the request argument on API, so we can see what was passed.
ArgumentCaptor<GraphQLRequest<ModelWithMetadata<Item>>> requestCaptor = ArgumentCaptor.forClass(GraphQLRequest.class);
verify(api).mutate(requestCaptor.capture(), any(Consumer.class), any(Consumer.class));
GraphQLRequest<ModelWithMetadata<Item>> capturedRequest = requestCaptor.getValue();
// Assert
assertEquals(TypeMaker.getParameterizedType(ModelWithMetadata.class, Item.class), capturedRequest.getResponseType());
JSONAssert.assertEquals(Resources.readAsString("delete-item.txt"), capturedRequest.getContent(), true);
}
use of com.amplifyframework.testmodels.ecommerce.Item 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.testmodels.ecommerce.Item in project amplify-android by aws-amplify.
the class AppSyncGraphQLRequestFactoryTest 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 {
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"), AppSyncGraphQLRequestFactory.buildMutation(item, QueryPredicates.all(), MutationType.DELETE).getContent(), true);
}
Aggregations