use of com.amplifyframework.testmodels.commentsblog.Blog in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterObserveQueryTest method querySavedDataWithPredicatesOnForeignKey.
/**
* Test querying with predicate condition on connected model.
*
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
* @throws InterruptedException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithPredicatesOnForeignKey() throws DataStoreException, InterruptedException {
final BlogOwner blogOwner = BlogOwner.builder().name("Jane Doe").build();
adapter.save(blogOwner);
final Blog blog = Blog.builder().name("Jane's Commercial Real Estate Blog").owner(blogOwner).build();
adapter.save(blog);
CountDownLatch latch = new CountDownLatch(1);
Consumer<Cancelable> observationStarted = NoOpConsumer.create();
Consumer<DataStoreQuerySnapshot<Blog>> onQuerySnapshot = value -> {
assertTrue(value.getItems().contains(blog));
latch.countDown();
};
Consumer<DataStoreException> onObservationError = NoOpConsumer.create();
Action onObservationComplete = NoOpAction.create();
adapter.observeQuery(Blog.class, new ObserveQueryOptions(BlogOwner.NAME.eq("Jane Doe"), null), observationStarted, onQuerySnapshot, onObservationError, onObservationComplete);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.amplifyframework.testmodels.commentsblog.Blog in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterObserveQueryTest method querySavedDataWithForeignKey.
/**
* Test that querying the saved item with a foreign key with observeQuery
* also populates that instance variable with object.
*
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
* @throws InterruptedException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithForeignKey() throws DataStoreException, InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
final BlogOwner blogOwner = BlogOwner.builder().name("Alan Turing").build();
final Blog blog = Blog.builder().name("Alan's Software Blog").owner(blogOwner).build();
adapter.save(blogOwner);
adapter.save(blog);
Consumer<Cancelable> observationStarted = NoOpConsumer.create();
Consumer<DataStoreQuerySnapshot<Blog>> onQuerySnapshot = value -> {
assertTrue(value.getItems().contains(blog));
latch.countDown();
};
Consumer<DataStoreException> onObservationError = NoOpConsumer.create();
Action onObservationComplete = NoOpAction.create();
adapter.observeQuery(Blog.class, new ObserveQueryOptions(null, null), observationStarted, onQuerySnapshot, onObservationError, onObservationComplete);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.amplifyframework.testmodels.commentsblog.Blog in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method querySavedDataWithPredicatesOnForeignKey.
/**
* Test querying with predicate condition on connected model.
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void querySavedDataWithPredicatesOnForeignKey() throws DataStoreException {
final BlogOwner blogOwner = BlogOwner.builder().name("Jane Doe").build();
adapter.save(blogOwner);
final Blog blog = Blog.builder().name("Jane's Commercial Real Estate Blog").owner(blogOwner).build();
adapter.save(blog);
final List<Blog> blogsOwnedByJaneDoe = adapter.query(Blog.class, Where.matches(BlogOwner.NAME.eq("Jane Doe")));
assertTrue(blogsOwnedByJaneDoe.contains(blog));
}
use of com.amplifyframework.testmodels.commentsblog.Blog in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method queryFieldsAreBackwardsCompatible.
/**
* Test that new QueryField with explicit model name produces the same result as old QueryField.
* @throws DataStoreException On failure to arrange items into store, or from the query action itself
*/
@Test
public void queryFieldsAreBackwardsCompatible() throws DataStoreException {
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);
final int numModels = 10;
for (int counter = 0; counter < numModels; counter++) {
final Post post = Post.builder().title("title " + counter).status(PostStatus.INACTIVE).rating(counter).blog(blog).build();
adapter.save(post);
}
// Assert that using QueryField without model name yields same results if there is no column ambiguity
assertEquals(adapter.query(Post.class, Where.matches(field("Post", "title").contains("4"))), adapter.query(Post.class, Where.matches(field("title").contains("4"))));
assertEquals(adapter.query(Post.class, Where.matches(field("Post", "rating").gt(3))), adapter.query(Post.class, Where.matches(field("rating").gt(3))));
}
use of com.amplifyframework.testmodels.commentsblog.Blog in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterQueryTest method querySavedDataWithForeignKey.
/**
* 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 querySavedDataWithForeignKey() throws DataStoreException {
final BlogOwner blogOwner = BlogOwner.builder().name("Alan Turing").build();
final Blog blog = Blog.builder().name("Alan's Software Blog").owner(blogOwner).build();
adapter.save(blogOwner);
adapter.save(blog);
final List<Blog> blogs = adapter.query(Blog.class);
assertTrue(blogs.contains(blog));
}
Aggregations