Search in sources :

Example 1 with Team

use of com.amplifyframework.testmodels.teamproject.Team in project amplify-android by aws-amplify.

the class CodeGenerationInstrumentationTest method belongsToRelationship.

/**
 * For a model having an {@link BelongsTo} relationship to another model, validate
 * successful query, mutations, subscription.
 * TODO: Add mutate with condition and list with predicate since those are the ones
 *       that actually use the original model name
 * @throws ApiException On failure to obtain valid response from endpoint
 */
@Test
public void belongsToRelationship() throws ApiException {
    // Subscribe to creation events for any Projectfields
    TestObserver<GraphQLResponse<Projectfields>> observer = api.onCreate(PROJECT_API_NAME, Projectfields.class).test();
    // Create a team
    Team team = Team.builder().name("AWS Mobile SDK").build();
    Team createdTeam = api.create(PROJECT_API_NAME, team);
    // Create a Projectfields
    Projectfields projectfields = Projectfields.builder().name("API Codegen").team(Team.justId(createdTeam.getId())).build();
    Projectfields createdProjectfields = api.create(PROJECT_API_NAME, projectfields);
    // Query for the Projectfields that were just created. The referenced team
    // should be the same as the one we requested for creation, earlier.
    assertEquals(team, api.get(PROJECT_API_NAME, Projectfields.class, createdProjectfields.getId()).getTeam());
    // Validate that subscription received the newly created team, too.
    Projectfields projectfieldsOnSubscription = observer.awaitCount(1).values().get(0).getData();
    assertEquals(projectfields.getName(), projectfieldsOnSubscription.getName());
    assertEquals(team, projectfieldsOnSubscription.getTeam());
    // Cancel the subscription
    observer.dispose();
}
Also used : GraphQLResponse(com.amplifyframework.api.graphql.GraphQLResponse) Team(com.amplifyframework.testmodels.teamproject.Team) Projectfields(com.amplifyframework.testmodels.teamproject.Projectfields) Test(org.junit.Test)

Aggregations

GraphQLResponse (com.amplifyframework.api.graphql.GraphQLResponse)1 Projectfields (com.amplifyframework.testmodels.teamproject.Projectfields)1 Team (com.amplifyframework.testmodels.teamproject.Team)1 Test (org.junit.Test)1