use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validatePredicateOperationForSyncExpressionIsWrappedWithAnd.
/**
* If a QueryPredicateOperation is provided, it should be wrapped in an AND group. This enables AppSync to
* optimize by performing an DDB query instead of scan.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validatePredicateOperationForSyncExpressionIsWrappedWithAnd() throws AmplifyException, JSONException {
String id = "426f8e8d-ea0f-4839-a73f-6a2a38565ba1";
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
final GraphQLRequest<Iterable<Post>> request = AppSyncRequestFactory.buildSyncRequest(schema, null, null, BlogOwner.ID.eq(id));
JSONAssert.assertEquals(Resources.readAsString("base-sync-request-with-predicate-operation.txt"), request.getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateSubscriptionGenerationOnCreateForNestedCustomType.
/**
* Validates that a GraphQL request document can be created, to get onCreate for nested custom type
* subscription notifications for a Parent.class.
* @throws DataStoreException On failure to interrogate the Blog.class.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validateSubscriptionGenerationOnCreateForNestedCustomType() throws AmplifyException, JSONException {
ModelSchema schema = ModelSchema.fromModelClass(Parent.class);
JSONAssert.assertEquals(Resources.readAsString("on-create-request-for-parent.txt"), AppSyncRequestFactory.buildSubscriptionRequest(schema, SubscriptionType.ON_CREATE, DEFAULT_STRATEGY).getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateSubscriptionGenerationOnUpdatePost.
/**
* Validates generation of a GraphQL document which requests a subscription for updates
* to the Blog.class.
* @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 validateSubscriptionGenerationOnUpdatePost() throws AmplifyException, JSONException {
ModelSchema schema = ModelSchema.fromModelClass(Post.class);
JSONAssert.assertEquals(Resources.readAsString("on-update-request-for-post.txt"), AppSyncRequestFactory.buildSubscriptionRequest(schema, SubscriptionType.ON_UPDATE, DEFAULT_STRATEGY).getContent(), true);
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class TopologicalOrdering method forRegisteredModels.
/**
* Gets a TopologicalOrdering of the ModelSchema in the SchemaRegistry.
* The set of ModelSchema in that registry is not expected to change during runtime,
* so the results of this TopologicalOrdering should likewise be stable at runtime.
* @param schemaRegistry A registry of ModelSchema
* @param modelProvider A ModelProvider
* @return A topological ordering of the model schema in the registry
*/
@SuppressLint("SyntheticAccessor")
static TopologicalOrdering forRegisteredModels(@NonNull SchemaRegistry schemaRegistry, @NonNull ModelProvider modelProvider) {
Objects.requireNonNull(modelProvider);
final List<ModelSchema> schemaForModels = new ArrayList<>();
for (String modelClassName : modelProvider.modelNames()) {
final ModelSchema schemaForModelClass = schemaRegistry.getModelSchemaForModelClass(modelClassName);
schemaForModels.add(schemaForModelClass);
}
return new TopologicalOrdering(new TopologicalSort(schemaForModels).result());
}
use of com.amplifyframework.core.model.ModelSchema in project amplify-android by aws-amplify.
the class AppSyncClientTest method validateBaseSyncQueryGen.
/**
* Validates the construction of a base-sync query.
* @throws JSONException On bad request JSON found in API category call
* @throws DataStoreException If no valid response returned from AppSync endpoint during sync
* @throws AmplifyException On failure to arrange model schema
*/
@Test
public void validateBaseSyncQueryGen() throws JSONException, AmplifyException {
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
Await.result((Consumer<GraphQLResponse<PaginatedResult<ModelWithMetadata<BlogOwner>>>> onResult, Consumer<DataStoreException> onError) -> {
try {
GraphQLRequest<PaginatedResult<ModelWithMetadata<BlogOwner>>> request = endpoint.buildSyncRequest(schema, null, null, QueryPredicates.all());
endpoint.sync(request, onResult, onError);
} catch (DataStoreException datastoreException) {
onError.accept(datastoreException);
}
});
// Now, capture the request argument on API, so we can see what was passed.
// Recall that we pass a raw doc to API.
ArgumentCaptor<GraphQLRequest<ModelWithMetadata<BlogOwner>>> requestCaptor = ArgumentCaptor.forClass(GraphQLRequest.class);
verify(api).query(requestCaptor.capture(), any(Consumer.class), any(Consumer.class));
GraphQLRequest<ModelWithMetadata<BlogOwner>> capturedRequest = requestCaptor.getValue();
Type type = TypeMaker.getParameterizedType(PaginatedResult.class, ModelWithMetadata.class, BlogOwner.class);
assertEquals(type, capturedRequest.getResponseType());
// The request was sent as JSON. It has a null variables field, and a present query field.
JSONAssert.assertEquals(Resources.readAsString("base-sync-request-document-for-blog-owner.txt"), capturedRequest.getContent(), true);
}
Aggregations