use of com.amplifyframework.datastore.model.SimpleModelProvider in project amplify-android by aws-amplify.
the class TopologicalOrderingTest method orderingOfBlogPostComment.
/**
* Checks the topological ordering of the Blog, Post, and Comment classes.
* @throws AmplifyException On failure to load models into registry
*/
@Test
public void orderingOfBlogPostComment() throws AmplifyException {
// Load the models into the registry.
// They are provided intentionally out of topological order.
final SimpleModelProvider provider = SimpleModelProvider.withRandomVersion(Comment.class, Blog.class, BlogOwner.class, Post.class);
final SchemaRegistry registry = SchemaRegistry.instance();
registry.clear();
registry.register(provider.models());
// Find the schema that the registry created for each of the models.
ModelSchema commentSchema = findSchema(registry, Comment.class);
ModelSchema postSchema = findSchema(registry, Post.class);
ModelSchema blogSchema = findSchema(registry, Blog.class);
// Act: get a topological ordering of the models.
TopologicalOrdering topologicalOrdering = TopologicalOrdering.forRegisteredModels(registry, provider);
// Assert: Blog comes before Post, and Post comes before Comment.
assertTrue(topologicalOrdering.check(blogSchema).isBefore(postSchema));
assertTrue(topologicalOrdering.check(postSchema).isBefore(commentSchema));
// Assert: in other words, Comment is after Post, and Post is after Blog.
assertTrue(topologicalOrdering.check(commentSchema).isAfter(postSchema));
assertTrue(topologicalOrdering.check(postSchema).isAfter(blogSchema));
}
Aggregations