Search in sources :

Example 86 with ModelSchema

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);
}
Also used : ModelSchema(com.amplifyframework.core.model.ModelSchema) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 87 with ModelSchema

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

Example 88 with ModelSchema

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);
}
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 89 with ModelSchema

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

Example 90 with ModelSchema

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

Aggregations

ModelSchema (com.amplifyframework.core.model.ModelSchema)109 Test (org.junit.Test)69 SerializedModel (com.amplifyframework.core.model.SerializedModel)34 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)30 Model (com.amplifyframework.core.model.Model)28 DataStoreException (com.amplifyframework.datastore.DataStoreException)26 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)22 SchemaRegistry (com.amplifyframework.core.model.SchemaRegistry)21 AmplifyException (com.amplifyframework.AmplifyException)19 Consumer (com.amplifyframework.core.Consumer)19 List (java.util.List)17 NonNull (androidx.annotation.NonNull)14 Cancelable (com.amplifyframework.core.async.Cancelable)14 TimeUnit (java.util.concurrent.TimeUnit)14 QueryPredicate (com.amplifyframework.core.model.query.predicate.QueryPredicate)13 Action (com.amplifyframework.core.Action)12 ModelWithMetadata (com.amplifyframework.datastore.appsync.ModelWithMetadata)12 Collections (java.util.Collections)12 ModelProvider (com.amplifyframework.core.model.ModelProvider)11