Search in sources :

Example 1 with Item

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);
}
Also used : Item(com.amplifyframework.testmodels.ecommerce.Item) ModelSchema(com.amplifyframework.core.model.ModelSchema) GraphQLRequest(com.amplifyframework.api.graphql.GraphQLRequest) Temporal(com.amplifyframework.core.model.temporal.Temporal) Consumer(com.amplifyframework.core.Consumer) Test(org.junit.Test)

Example 2 with Item

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);
}
Also used : ModelSchema(com.amplifyframework.core.model.ModelSchema) Item(com.amplifyframework.testmodels.ecommerce.Item) Temporal(com.amplifyframework.core.model.temporal.Temporal) Test(org.junit.Test)

Example 3 with Item

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);
}
Also used : Item(com.amplifyframework.testmodels.ecommerce.Item) Temporal(com.amplifyframework.core.model.temporal.Temporal) Test(org.junit.Test)

Aggregations

Temporal (com.amplifyframework.core.model.temporal.Temporal)3 Item (com.amplifyframework.testmodels.ecommerce.Item)3 Test (org.junit.Test)3 ModelSchema (com.amplifyframework.core.model.ModelSchema)2 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)1 Consumer (com.amplifyframework.core.Consumer)1