use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method querySavedDataWithMultiLevelJoins.
/**
* Test that querying the saved item with a foreign key
* also populates that instance variable with object.
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithMultiLevelJoins() throws DataStoreException {
final BlogOwner blogOwner = BlogOwner.builder().name("Alan Turing").build();
final Blog blog = Blog.builder().name("Alan's Software Blog").owner(blogOwner).build();
final Post post = Post.builder().title("Alan's first post").status(PostStatus.ACTIVE).rating(2).blog(blog).build();
final Comment comment = Comment.builder().content("Alan's first comment").post(post).build();
adapter.save(blogOwner);
adapter.save(blog);
adapter.save(post);
adapter.save(comment);
final List<Comment> comments = adapter.query(Comment.class);
assertTrue(comments.contains(comment));
assertEquals(comments.get(0).getPost(), post);
assertEquals(comments.get(0).getPost().getBlog(), blog);
assertEquals(comments.get(0).getPost().getBlog().getOwner(), blogOwner);
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method querySavedDataWithNumericalPredicates.
/**
* Test querying the saved item in the SQLite database with
* predicate conditions.
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithNumericalPredicates() throws DataStoreException {
final List<Post> savedModels = new ArrayList<>();
final int numModels = 10;
BlogOwner blogOwner = BlogOwner.builder().name("Test Dummy").build();
adapter.save(blogOwner);
Blog blog = Blog.builder().name("Blogging for Dummies").owner(blogOwner).build();
adapter.save(blog);
for (int counter = 0; counter < numModels; counter++) {
final Post post = Post.builder().title("titlePrefix:" + counter).status(PostStatus.INACTIVE).rating(counter).blog(blog).build();
adapter.save(post);
savedModels.add(post);
}
// 1, 4, 5, 6
QueryPredicate predicate = Post.RATING.ge(4).and(Post.RATING.lt(7)).or(Post.RATING.eq(1).and(Post.RATING.ne(7)));
assertEquals(Observable.fromArray(1, 4, 5, 6).map(savedModels::get).toList().map(HashSet::new).blockingGet(), Observable.fromIterable(adapter.query(Post.class, Where.matches(predicate))).toList().map(HashSet::new).blockingGet());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method queryWithOrderByRelatedModel.
/**
* Test query with order by. Validate that a list of Blog can be sorted by the names of BlogOwners.
* @throws DataStoreException On failure to arrange items into store, or from the query action itself
*/
@Test
public void queryWithOrderByRelatedModel() throws DataStoreException {
// Expect: Create BlogOwners and their respective blogs
List<String> names = Arrays.asList("Joe", "Bob", "Dan", "Jane");
List<Blog> blogs = new ArrayList<>();
for (String name : names) {
BlogOwner owner = BlogOwner.builder().name(name).build();
adapter.save(owner);
Blog blog = Blog.builder().name("").owner(owner).build();
adapter.save(blog);
blogs.add(blog);
}
// Act: Query Blogs sorted by owner's name
List<Blog> result = adapter.query(Blog.class, Where.sorted(BlogOwner.NAME.ascending()));
// Verify: Query result is sorted by owner's name
List<Blog> sorted = new ArrayList<>(blogs);
Collections.sort(sorted, Comparator.comparing(blog -> blog.getOwner().getName()));
assertEquals(sorted, result);
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method querySavedDataWithMultipleItems.
/**
* Test querying the saved item in the SQLite database.
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithMultipleItems() throws DataStoreException {
final List<BlogOwner> savedModels = new ArrayList<>();
final int numModels = 10;
for (int counter = 0; counter < numModels; counter++) {
final BlogOwner blogOwner = BlogOwner.builder().name("namePrefix:" + counter).build();
adapter.save(blogOwner);
savedModels.add(blogOwner);
}
assertEquals(Observable.fromIterable(savedModels).toList().map(HashSet::new).blockingGet(), Observable.fromIterable(adapter.query(BlogOwner.class)).toList().map(HashSet::new).blockingGet());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class HybridAssociationSyncInstrumentationTest method associatedModelAreSyncedDownFromCloud.
/**
* When the cloud sees an update to its data, the new data should be reflected in the
* local store. What's more, we should be able to query for the updated data by its model names,
* and expect to see the result, that way. This should hold for associated models, too.
* @throws AmplifyException For a variety of reasons, including failure to build schema,
* or bad interaction with API or DataStore
*/
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Test
public void associatedModelAreSyncedDownFromCloud() throws AmplifyException {
// Create a BlogOwner on the remote system,
// and wait for it to trickle back to the client.
BlogOwner owner = BlogOwner.builder().name("Agent Texas").build();
String ownerModelName = BlogOwner.class.getSimpleName();
ModelSchema ownerSchema = schemaProvider.modelSchemas().get(ownerModelName);
assertNotNull(ownerSchema);
HubAccumulator ownerAccumulator = HubAccumulator.create(HubChannel.DATASTORE, receiptOf(owner.getId()), 1).start();
appSync.create(owner, ownerSchema);
ownerAccumulator.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
// Now, validate that we see the data locally, when we query for serialized models
// and by Java BlogOwners.
Map<String, Object> expectedOwnerData = new HashMap<>();
expectedOwnerData.put("id", owner.getId());
expectedOwnerData.put("name", owner.getName());
List<SerializedModel> actualSerializedOwners = hybridBehaviors.list(ownerSchema.getName());
assertTrue(actualSerializedOwners.contains(SerializedModel.builder().serializedData(expectedOwnerData).modelSchema(ownerSchema).build()));
assertTrue(normalBehaviors.list(BlogOwner.class).contains(owner));
// Now, remotely save a model that has an association to the owner above.
Blog blog = Blog.builder().name("Blog about Texas").owner(owner).build();
String blogModelName = Blog.class.getSimpleName();
ModelSchema blogSchema = schemaProvider.modelSchemas().get(blogModelName);
assertNotNull(blogSchema);
HubAccumulator blogAccumulator = HubAccumulator.create(HubChannel.DATASTORE, receiptOf(blog.getId()), 1).start();
appSync.create(blog, blogSchema);
blogAccumulator.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
// Validate that we can find the newly associated model locally, now.
Map<String, Object> expectedBlogData = new HashMap<>();
expectedBlogData.put("id", blog.getId());
expectedBlogData.put("name", blog.getName());
expectedBlogData.put("owner", SerializedModel.builder().serializedData(Collections.singletonMap("id", owner.getId())).modelSchema(null).build());
List<SerializedModel> expectedSerializedBlogs = hybridBehaviors.list(blogSchema.getName());
assertTrue(expectedSerializedBlogs.contains(SerializedModel.builder().serializedData(expectedBlogData).modelSchema(blogSchema).build()));
assertTrue(normalBehaviors.list(Blog.class).contains(blog));
}
Aggregations