Search in sources :

Example 1 with Rating

use of com.amplifyframework.testmodels.ratingsblog.Rating in project amplify-android by aws-amplify.

the class CodeGenerationInstrumentationTest method hasOneRelationship.

/**
 * Tests the code generation for HAS_ONE relationship.
 * @throws ApiException On failure to obtain valid response from endpoint
 */
@Test
public void hasOneRelationship() throws ApiException {
    // Create a blog
    Blog blog = Blog.builder().name("Necessary blog for post").build();
    api.create(BLOG_API_NAME, blog);
    // Associate a post to that blog
    Post post = Post.builder().title("Test post").blog(blog).build();
    api.create(BLOG_API_NAME, post);
    // Make a ating for the post
    Rating rating = Rating.builder().stars(5).post(post).build();
    Rating createdRating = api.create(BLOG_API_NAME, rating);
    // Validate that rating that exists on the endpoint refers to the original post
    assertEquals(post, createdRating.getPost());
/*
        TODO: This condition should work. However there is a bug on the AppSync transformer side which
            sets up the HasOne / BelongsTo relationship as two independent BelongsTo relationships so it fails.
            Once the AppSync transformer bug is fixed, we can uncomment this part of the test.

        assertEquals(
            rating,
            api.get(BLOG_API_NAME, Post.class, post.getId())
                .getRating()
        );
        */
}
Also used : Post(com.amplifyframework.testmodels.ratingsblog.Post) Rating(com.amplifyframework.testmodels.ratingsblog.Rating) Blog(com.amplifyframework.testmodels.ratingsblog.Blog) Test(org.junit.Test)

Aggregations

Blog (com.amplifyframework.testmodels.ratingsblog.Blog)1 Post (com.amplifyframework.testmodels.ratingsblog.Post)1 Rating (com.amplifyframework.testmodels.ratingsblog.Rating)1 Test (org.junit.Test)1