use of com.amplifyframework.api.graphql.SubscriptionType in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method arrangeStartedSubscriptions.
private static void arrangeStartedSubscriptions(AppSync appSync, List<ModelSchema> modelSchemas, SubscriptionType[] subscriptionTypes) {
Answer<Cancelable> answer = invocation -> {
final int startConsumerIndex = 1;
Consumer<String> onStart = invocation.getArgument(startConsumerIndex);
onStart.accept(RandomString.string());
return new NoOpCancelable();
};
arrangeSubscriptions(appSync, answer, modelSchemas, subscriptionTypes);
}
use of com.amplifyframework.api.graphql.SubscriptionType in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method appSyncInvokedWhenSubscriptionsStarted.
/**
* When {@link SubscriptionProcessor#startSubscriptions()} is invoked,
* the {@link AppSync} client receives subscription requests.
*/
@Test
public void appSyncInvokedWhenSubscriptionsStarted() {
// For every Class-SubscriptionType pairing, use a CountDownLatch
// to tell whether or not we've "seen" a subscription event for it.
Map<Pair<ModelSchema, SubscriptionType>, CountDownLatch> seen = new HashMap<>();
// Build a stream of such pairs.
Observable.fromIterable(modelSchemas).flatMap(modelSchema -> Observable.fromArray(SubscriptionType.values()).map(value -> Pair.create(modelSchema, value))).blockingForEach(pair -> {
// For each one, store a latch. Add a mocking behavior to count down
// the latch when the subscription API is hit, for that class and subscription type.
CountDownLatch latch = new CountDownLatch(1);
seen.put(Pair.create(pair.first, pair.second), latch);
Answer<Cancelable> answer = invocation -> {
latch.countDown();
return new NoOpCancelable();
};
arrangeSubscription(appSync, answer, pair.first, pair.second);
});
// Act: start some subscriptions.
try {
subscriptionProcessor.startSubscriptions();
} catch (DataStoreException exception) {
// startSubscriptions throws this exception if it doesn't receive the start_ack messages after a time out.
// This test doesn't mock those start_ack messages, so this expection is expected. That's okay though -
// we just want to verify that the subscriptions were requested.
}
// Make sure that all of the subscriptions have been
Observable.fromIterable(seen.entrySet()).blockingForEach(entry -> {
CountDownLatch latch = entry.getValue();
assertTrue(latch.await(OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS));
});
}
use of com.amplifyframework.api.graphql.SubscriptionType in project amplify-android by aws-amplify.
the class AuthRuleRequestDecoratorTest method ownerArgumentAddedForRestrictedReadWithOidc.
/**
* Verify that owner argument is required for all subscriptions if ModelOperation.READ is specified
* while using OpenID Connect auth mode.
* @throws AmplifyException if a ModelSchema can't be derived from the Model class.
*/
@Test
public void ownerArgumentAddedForRestrictedReadWithOidc() throws AmplifyException {
final AuthorizationType mode = AuthorizationType.OPENID_CONNECT;
final String expectedOwner = FakeOidcAuthProvider.SUB;
// OwnerOidc class has restriction on every operation including READ
for (SubscriptionType subscriptionType : SubscriptionType.values()) {
GraphQLRequest<OwnerOidc> originalRequest = createRequest(OwnerOidc.class, subscriptionType);
GraphQLRequest<OwnerOidc> modifiedRequest = decorator.decorate(originalRequest, mode);
assertEquals(expectedOwner, getOwnerField(modifiedRequest));
}
}
use of com.amplifyframework.api.graphql.SubscriptionType in project amplify-android by aws-amplify.
the class AuthRuleRequestDecoratorTest method ownerArgumentAddedIfOwnerIsNotInGroupWithUserPools.
/**
* Verify owner argument is added if model contains both owner-based and group-based
* authorization and the user is not in any read-restricted group.
* @throws AmplifyException if a ModelSchema can't be derived from the Model class.
*/
@Test
public void ownerArgumentAddedIfOwnerIsNotInGroupWithUserPools() throws AmplifyException {
final AuthorizationType mode = AuthorizationType.AMAZON_COGNITO_USER_POOLS;
final String expectedOwner = FakeCognitoAuthProvider.USERNAME;
// but user is not in the read-restricted group.
for (SubscriptionType subscriptionType : SubscriptionType.values()) {
GraphQLRequest<OwnerNotInGroup> originalRequest = createRequest(OwnerNotInGroup.class, subscriptionType);
GraphQLRequest<OwnerNotInGroup> modifiedRequest = decorator.decorate(originalRequest, mode);
assertEquals(expectedOwner, getOwnerField(modifiedRequest));
}
}
use of com.amplifyframework.api.graphql.SubscriptionType in project amplify-android by aws-amplify.
the class AuthRuleRequestDecoratorTest method ownerArgumentNotAddedIfOwnerIsInGroupWithUserPools.
/**
* Verify owner argument is NOT added if model contains both owner-based and group-based
* authorization and the user is in any of the read-restricted groups.
* @throws AmplifyException if a ModelSchema can't be derived from the Model class.
*/
@Test
public void ownerArgumentNotAddedIfOwnerIsInGroupWithUserPools() throws AmplifyException {
final AuthorizationType mode = AuthorizationType.AMAZON_COGNITO_USER_POOLS;
// and user is in the read-restricted group.
for (SubscriptionType subscriptionType : SubscriptionType.values()) {
GraphQLRequest<OwnerInGroup> originalRequest = createRequest(OwnerInGroup.class, subscriptionType);
GraphQLRequest<OwnerInGroup> modifiedRequest = decorator.decorate(originalRequest, mode);
assertNull(getOwnerField(modifiedRequest));
}
}
Aggregations