use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class AppSyncClientUnitTest method setup.
@Before
public void setup() {
shadowContext = RuntimeEnvironment.application;
mockContext = Mockito.mock(Context.class);
mockLogger = Mockito.mock(ApolloLogger.class);
mockSubscription = Mockito.mock(Subscription.class);
mockSubscriptionManager = Mockito.mock(SubscriptionManager.class);
mockApolloClient = Mockito.mock(ApolloClient.class);
mockSubscriptionMetadataRequest = Mockito.mock(RealAppSyncCall.class);
res = Mockito.mock(Resources.class);
Mockito.when(mockContext.getResources()).thenReturn(res);
jsonConfig = "{\n" + " \"CredentialsProvider\": {\n" + " \"CognitoIdentity\": {\n" + " \"AwsIam\": {\n" + " \"PoolId\": \"us-east-1:xxxx\",\n" + " \"Region\": \"us-east-1\"\n" + " }\n" + " }\n" + " },\n" + " \"CognitoUserPool\": {\n" + " \"AmazonCognitoUserPools\": {\n" + " \"PoolId\": \"us-east-1_zzzz\",\n" + " \"AppClientId\": \"aaaa\",\n" + " \"AppClientSecret\": \"bbbb\",\n" + " \"Region\": \"us-east-1\"\n" + " }\n" + " },\n" + " \"AppSync\": {\n" + " \"Default\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"ApiKey\": \"da2-xxxx\",\n" + " \"AuthMode\": \"API_KEY\"\n" + " },\n" + " \"ApiKey\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"ApiKey\": \"da2-xxxx\",\n" + " \"AuthMode\": \"API_KEY\",\n" + " \"ClientDatabasePrefix\": \"prefix_from_config\"\n" + " },\n" + " \"AwsIam\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"AuthMode\": \"AWS_IAM\"\n" + " },\n" + " \"AmazonCognitoUserPools\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"AuthMode\": \"AMAZON_COGNITO_USER_POOLS\"\n" + " },\n" + " \"OpenidConnect\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"AuthMode\": \"OPENID_CONNECT\"\n" + " },\n" + " \"Lambda\": {\n" + " \"ApiUrl\": \"https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\",\n" + " \"Region\": \"us-east-1\",\n" + " \"AuthMode\": \"AWS_LAMBDA\"\n" + " }\n" + " }\n" + "}";
Mockito.when(res.openRawResource(3213210)).thenReturn(new ByteArrayInputStream(jsonConfig.getBytes()));
awsConfiguration = new AWSConfiguration(mockContext, 3213210);
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testConfigHasInvalidClientDatabasePrefix.
@Test
public void testConfigHasInvalidClientDatabasePrefix() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_InvalidClientDatabasePrefix");
RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).useClientDatabasePrefix(true).build());
String expected = "ClientDatabasePrefix validation failed. Please pass in characters " + "that matches the pattern: ^[_a-zA-Z0-9]+$";
assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasEmptyClientDatabasePrefix.
@Test
public void testCodeHasEmptyClientDatabasePrefix() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(// Note: this is the problem!!
"").build());
String expected = "Please pass in a valid ClientDatabasePrefix when useClientDatabasePrefix is true.";
assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixTrue.
@Test
public void testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixTrue() throws JSONException {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
AWSAppSyncClient.Builder awsAppSyncClientBuilder = AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix"));
AWSAppSyncClient awsAppSyncClient = awsAppSyncClientBuilder.build();
AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, appSyncConfig.getString("ClientDatabasePrefix"), appSyncConfig.getString("AuthMode"));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixFalse.
@Test
public void testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixFalse() throws JSONException {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(false).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build();
AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, null, null);
}
Aggregations