use of com.amplifyframework.testmodels.ratingsblog.User in project amplify-android by aws-amplify.
the class CodeGenerationInstrumentationTest method manyToManyRelationship.
/**
* Tests the code generation for a Many to Many relationship simulated through two HasMany relationships.
* @throws ApiException On failure to obtain valid response from endpoint
*/
@Test
public void manyToManyRelationship() throws ApiException {
// Create a blog.
Blog blog = Blog.builder().name("Necessary blog for post").build();
api.create(BLOG_API_NAME, blog);
// Which contains a post
Post post = Post.builder().title("Test post").blog(blog).build();
api.create(BLOG_API_NAME, post);
// Create a user
User user = User.builder().username("Patches46").build();
api.create(BLOG_API_NAME, user);
// The user is an editor of the created post
PostEditor editor = PostEditor.builder().post(post).editor(user).build();
api.create(BLOG_API_NAME, editor);
// Now, see what was actually setup on the endpoint, by querying for post and user
Post queriedPost = api.get(BLOG_API_NAME, Post.class, post.getId());
User queriedUser = api.get(BLOG_API_NAME, User.class, user.getId());
// Validate that associations are setup correctly on the objects returned from endpoint
// The post should refer to the user, and the user should refer to the post.
assertEquals(1, queriedPost.getEditors().size());
assertEquals(user, queriedPost.getEditors().get(0).getEditor());
assertEquals(1, queriedUser.getPosts().size());
assertEquals(post.getTitle(), queriedUser.getPosts().get(0).getPost().getTitle());
assertEquals(post.getId(), queriedUser.getPosts().get(0).getPost().getId());
}
use of com.amplifyframework.testmodels.ratingsblog.User in project amplify-android by aws-amplify.
the class FieldFinderTest method extractsSerializedModelFieldValue.
/**
* Extracts the field value for a serialized model.
* @throws AmplifyException On failure to derive ModelSchema or to convert Java model to Map
* @throws NoSuchFieldException If field name does not exist for model
*/
@Test
public void extractsSerializedModelFieldValue() throws AmplifyException, NoSuchFieldException {
String username = "foo";
User user = User.builder().username(username).build();
ModelSchema modelSchema = ModelSchema.fromModelClass(User.class);
Map<String, Object> map = ModelConverter.toMap(user, modelSchema);
SerializedModel serializedModel = SerializedModel.builder().serializedData(map).modelSchema(modelSchema).build();
Object extractedValue = FieldFinder.extractFieldValue(serializedModel, "username");
Assert.assertEquals(username, extractedValue);
}
use of com.amplifyframework.testmodels.ratingsblog.User in project amplify-android by aws-amplify.
the class FieldFinderTest method extractsModelFieldValue.
/**
* Extracts the field value for a model.
* @throws NoSuchFieldException If field name does not exist for model
*/
@Test
public void extractsModelFieldValue() throws NoSuchFieldException {
String username = "foo";
User user = User.builder().username(username).build();
Object extractedValue = FieldFinder.extractFieldValue(user, "username");
Assert.assertEquals(username, extractedValue);
}
Aggregations