Search in sources :

Example 1 with Meeting

use of com.amplifyframework.testmodels.meeting.Meeting in project amplify-android by aws-amplify.

the class AppSyncClientTest method validateUpdateMutationWithDates.

/**
 * Validates date serialization when creating mutation.
 * @throws JSONException from JSONAssert.assertEquals JSON parsing error
 * @throws AmplifyException from ModelSchema.fromModelClass to convert model to schema
 */
@Test
public void validateUpdateMutationWithDates() throws JSONException, AmplifyException {
    // Act: build a mutation to create a Meeting
    final Meeting meeting = Meeting.builder().name("meeting1").id("45a5f600-8aa8-41ac-a529-aed75036f5be").date(new Temporal.Date("2001-02-03")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15Z")).time(new Temporal.Time("01:22:33")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build();
    endpoint.update(meeting, ModelSchema.fromModelClass(Meeting.class), 1, response -> {
    }, error -> {
    });
    // Now, capture the request argument on API, so we can see what was passed.
    ArgumentCaptor<GraphQLRequest<ModelWithMetadata<Meeting>>> requestCaptor = ArgumentCaptor.forClass(GraphQLRequest.class);
    verify(api).mutate(requestCaptor.capture(), any(Consumer.class), any(Consumer.class));
    GraphQLRequest<ModelWithMetadata<Meeting>> capturedRequest = requestCaptor.getValue();
    // Assert
    assertEquals(TypeMaker.getParameterizedType(ModelWithMetadata.class, Meeting.class), capturedRequest.getResponseType());
    JSONAssert.assertEquals(Resources.readAsString("update-meeting.txt"), capturedRequest.getContent(), true);
}
Also used : GraphQLRequest(com.amplifyframework.api.graphql.GraphQLRequest) Temporal(com.amplifyframework.core.model.temporal.Temporal) Consumer(com.amplifyframework.core.Consumer) Meeting(com.amplifyframework.testmodels.meeting.Meeting) Test(org.junit.Test)

Example 2 with Meeting

use of com.amplifyframework.testmodels.meeting.Meeting in project amplify-android by aws-amplify.

the class HybridTemporalSyncInstrumentationTest method temporalTypesAreSyncedDownFromCloud.

/**
 * It is possible to receive a model with temporal types over a subscription.
 * After receiving such a model, we can query it locally and inspect its fields.
 * The temporal values should be the same as what was saved remotely.
 * @throws DataStoreException on failure to interact with AppSync
 */
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Test
public void temporalTypesAreSyncedDownFromCloud() throws DataStoreException {
    // Save a meeting, remotely. Wait for it to show up locally.
    Meeting meeting = createMeeting();
    HubAccumulator receiptAccumulator = HubAccumulator.create(HubChannel.DATASTORE, receiptOf(meeting.getId()), 1).start();
    appSync.create(meeting, modelSchema);
    receiptAccumulator.awaitFirst(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    // Look through the models that now exist locally.
    // One of them should be the thing we just saved to the backend.
    // Any others will have come in through the base sync in @Before.
    // When we find the clone, validate its fields.
    List<SerializedModel> clonedMeetings = hybridBehaviors.list(modelSchema.getName());
    SerializedModel clone = findById(clonedMeetings, meeting.getId());
    assertEquals(toMap(meeting), clone.getSerializedData());
}
Also used : Meeting(com.amplifyframework.testmodels.meeting.Meeting) HubAccumulator(com.amplifyframework.testutils.HubAccumulator) SerializedModel(com.amplifyframework.core.model.SerializedModel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Meeting

use of com.amplifyframework.testmodels.meeting.Meeting in project amplify-android by aws-amplify.

the class HybridTemporalSyncInstrumentationTest method temporalTypesAreSyncedUpToCloud.

/**
 * It is possible to dispatch a model that contain temporal types. After publishing
 * such a model to the cloud, we can query AppSync and find it there.
 * @throws ApiException on failure to communicate with AppSync API in verification phase of test
 */
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Test
public void temporalTypesAreSyncedUpToCloud() throws ApiException {
    // Prepare a SerializedModel that we will save to DataStore.
    Meeting meeting = createMeeting();
    Map<String, Object> sentData = toMap(meeting);
    SerializedModel sentModel = SerializedModel.builder().serializedData(sentData).modelSchema(modelSchema).build();
    HubAccumulator publicationAccumulator = HubAccumulator.create(HubChannel.DATASTORE, publicationOf(modelSchema.getName(), sentModel.getId()), 1).start();
    hybridBehaviors.save(sentModel);
    publicationAccumulator.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    // Retrieve the model from AppSync.
    Meeting remoteMeeting = api.get(Meeting.class, sentModel.getId());
    // Inspect the fields of the data in AppSync, and prepare it into a map
    // that we can compare with what we sent. Are they the same? They should be.
    assertEquals(sentData, toMap(remoteMeeting));
}
Also used : Meeting(com.amplifyframework.testmodels.meeting.Meeting) HubAccumulator(com.amplifyframework.testutils.HubAccumulator) SerializedModel(com.amplifyframework.core.model.SerializedModel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Meeting

use of com.amplifyframework.testmodels.meeting.Meeting in project amplify-android by aws-amplify.

the class AppSyncGraphQLRequestFactoryTest method validateDateSerializer.

/**
 * Validates date serialization when creating GraphQLRequest.
 * @throws JSONException from JSONAssert.assertEquals JSON parsing error
 */
@Test
public void validateDateSerializer() throws JSONException {
    // Create expectation
    final Meeting meeting1 = Meeting.builder().name("meeting1").id("45a5f600-8aa8-41ac-a529-aed75036f5be").date(new Temporal.Date("2001-02-03")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15Z")).time(new Temporal.Time("01:22:33")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build();
    // Act: build a mutation to create a Meeting
    GraphQLRequest<Meeting> requestToCreateMeeting1 = AppSyncGraphQLRequestFactory.buildMutation(meeting1, QueryPredicates.all(), MutationType.CREATE);
    // Assert: expected is actual
    JSONAssert.assertEquals(Resources.readAsString("create-meeting1.txt"), requestToCreateMeeting1.getContent(), true);
}
Also used : Temporal(com.amplifyframework.core.model.temporal.Temporal) Meeting(com.amplifyframework.testmodels.meeting.Meeting) Test(org.junit.Test)

Example 5 with Meeting

use of com.amplifyframework.testmodels.meeting.Meeting in project amplify-android by aws-amplify.

the class GsonGraphQLResponseFactoryTest method awsDateTypesCanBeDeserialized.

/**
 * {@link Temporal.Date}, {@link Temporal.DateTime}, {@link Temporal.Time}, and {@link Temporal.Timestamp} all
 * have different JSON representations. It must be possible to recover the Java type which
 * models the JSON representation of each.
 * @throws ApiException If the response factory fails to construct a response,
 *                      perhaps because deserialization to one of these types
 *                      has failed.
 */
@Test
public void awsDateTypesCanBeDeserialized() throws ApiException {
    // Expect
    List<Meeting> expectedMeetings = Arrays.asList(Meeting.builder().name("meeting0").id("45a5f600-8aa8-41ac-a529-aed75036f5be").date(new Temporal.Date("2001-02-03")).dateTime(new Temporal.DateTime("2001-02-03T01:30Z")).time(new Temporal.Time("01:22")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build(), Meeting.builder().name("meeting1").id("45a5f600-8aa8-41ac-a529-aed75036f5be").date(new Temporal.Date("2001-02-03")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15Z")).time(new Temporal.Time("01:22:33")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build(), Meeting.builder().name("meeting2").id("7a3d5d76-667e-4714-a882-8c8e00a6ffc9").date(new Temporal.Date("2001-02-03Z")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15.444Z")).time(new Temporal.Time("01:22:33.444")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build(), Meeting.builder().name("meeting3").id("3a880283-5402-4ad7-bc41-052ca6edeba8").date(new Temporal.Date("2001-02-03+01:30")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15.444+05:30")).time(new Temporal.Time("01:22:33.444Z")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build(), Meeting.builder().name("meeting4").id("5dfc35eb-f75a-4848-9655-9b8ca813b74d").date(new Temporal.Date("2001-02-03+01:30:15")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15.444+05:30:15")).time(new Temporal.Time("01:22:33.444+05:30")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build(), Meeting.builder().name("meeting5").id("3ce161af-14e7-4880-843b-921838efdc9d").date(new Temporal.Date("2001-02-03+01:30:15")).dateTime(new Temporal.DateTime("2001-02-03T01:30:15.444+05:30:15")).time(new Temporal.Time("01:22:33.444+05:30:15")).timestamp(new Temporal.Timestamp(1234567890000L, TimeUnit.MILLISECONDS)).build());
    // Act
    final String responseString = Resources.readAsString("list-meetings-response.json");
    Type responseType = TypeMaker.getParameterizedType(PaginatedResult.class, Meeting.class);
    GraphQLRequest<PaginatedResult<Meeting>> request = buildDummyRequest(responseType);
    final GraphQLResponse<PaginatedResult<Meeting>> response = responseFactory.buildResponse(request, responseString);
    final Iterable<Meeting> actualMeetings = response.getData().getItems();
    // Assert
    assertEquals(expectedMeetings, actualMeetings);
}
Also used : Meeting(com.amplifyframework.testmodels.meeting.Meeting) PaginatedResult(com.amplifyframework.api.graphql.PaginatedResult) QueryType(com.amplifyframework.api.graphql.QueryType) Type(java.lang.reflect.Type) Temporal(com.amplifyframework.core.model.temporal.Temporal) Test(org.junit.Test)

Aggregations

Meeting (com.amplifyframework.testmodels.meeting.Meeting)5 Test (org.junit.Test)5 Temporal (com.amplifyframework.core.model.temporal.Temporal)3 SerializedModel (com.amplifyframework.core.model.SerializedModel)2 HubAccumulator (com.amplifyframework.testutils.HubAccumulator)2 Ignore (org.junit.Ignore)2 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)1 PaginatedResult (com.amplifyframework.api.graphql.PaginatedResult)1 QueryType (com.amplifyframework.api.graphql.QueryType)1 Consumer (com.amplifyframework.core.Consumer)1 Type (java.lang.reflect.Type)1