use of com.amplifyframework.testmodels.commentsblog.Comment in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateMutationGenerationOnCreateComment.
/**
* Validates creation of a "create a model" request.
* @throws DataStoreException 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 validateMutationGenerationOnCreateComment() throws AmplifyException, JSONException {
Post post = Post.justId("9a4295d6-8225-495a-a531-beffc8b7ae7d");
Comment comment = Comment.builder().id("426f8e8d-ea0f-4839-a73f-6a2a38565ba1").content("toast").post(post).build();
ModelSchema schema = ModelSchema.fromModelClass(Comment.class);
JSONAssert.assertEquals(Resources.readAsString("create-comment-request.txt"), AppSyncRequestFactory.buildCreationRequest(schema, comment, DEFAULT_STRATEGY).getContent(), true);
}
use of com.amplifyframework.testmodels.commentsblog.Comment in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterObserveQueryTest 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
* @throws InterruptedException On unexpected failure manipulating items in/out of DataStore
*/
// @Test
public void querySavedDataWithMultiLevelJoins() 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();
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);
Consumer<Cancelable> observationStarted = NoOpConsumer.create();
Consumer<DataStoreQuerySnapshot<Comment>> onQuerySnapshot = value -> {
assertTrue(value.getItems().contains(comment));
assertEquals(value.getItems().get(0).getPost(), post);
assertEquals(value.getItems().get(0).getPost().getBlog(), blog);
assertEquals(value.getItems().get(0).getPost().getBlog().getOwner(), blogOwner);
latch.countDown();
};
Consumer<DataStoreException> onObservationError = NoOpConsumer.create();
Action onObservationComplete = NoOpAction.create();
adapter.observeQuery(Comment.class, new ObserveQueryOptions(null, null), observationStarted, onQuerySnapshot, onObservationError, onObservationComplete);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.amplifyframework.testmodels.commentsblog.Comment 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.Comment in project amplify-android by aws-amplify.
the class BasicCloudSyncInstrumentationTest method createPost1WithCommentThenReassignCommentToPost2.
/**
* The test is to create a new Post with Comment, reassign Comment to a different Post.
* @throws DataStoreException On failure to save or query items from DataStore.
* @throws ApiException On failure to query the API.
*/
@Test
public void createPost1WithCommentThenReassignCommentToPost2() throws DataStoreException, ApiException {
// Setup
BlogOwner owner = BlogOwner.builder().name("Owner").build();
Blog blog = Blog.builder().name("MyBlog").owner(owner).build();
Post firstPost = Post.builder().title("First Post").status(PostStatus.ACTIVE).rating(3).blog(blog).build();
Post secondPost = Post.builder().title("Second Post").status(PostStatus.ACTIVE).rating(5).blog(blog).build();
Comment comment = Comment.builder().content("Some comment").post(firstPost).build();
String modelName = Comment.class.getSimpleName();
// Save first post and comment. Then verify that first post and comment were saved.
HubAccumulator accumulator = HubAccumulator.create(HubChannel.DATASTORE, publicationOf(modelName, comment.getId()), 1).start();
dataStore.save(owner);
dataStore.save(blog);
dataStore.save(firstPost);
dataStore.save(comment);
accumulator.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
Comment localComment = dataStore.get(Comment.class, comment.getId());
Assert.assertEquals(comment.getPost().getId(), localComment.getPost().getId());
Comment remoteComment = api.get(Comment.class, comment.getId());
Assert.assertEquals(comment.getPost().getId(), remoteComment.getPost().getId());
// Reassign comment to second post, save and sync
Comment commentCopy = comment.copyOfBuilder().post(secondPost).build();
accumulator = HubAccumulator.create(HubChannel.DATASTORE, publicationOf(modelName, commentCopy.getId()), 1).start();
dataStore.save(secondPost);
dataStore.save(commentCopy);
accumulator.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
// Verify that comment was reassigned
Comment currentLocalComment = dataStore.get(Comment.class, comment.getId());
Assert.assertEquals(secondPost.getId(), currentLocalComment.getPost().getId());
Comment currentRemoteComment = api.get(Comment.class, comment.getId());
Assert.assertEquals(secondPost.getId(), currentRemoteComment.getPost().getId());
}
Aggregations