use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testUseSameClientDatabasePrefixForDifferentAuthModes.
@Test
public void testUseSameClientDatabasePrefixForDifferentAuthModes() throws JSONException {
// Construct client-1 with API_KEY AuthMode and MultiAuthAndroidIntegTestApp_API_KEY prefix
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
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")).build();
// Construct client-2 with AWS_IAM AuthMode and same prefix ("MultiAuthAndroidIntegTestApp_API_KEY")
RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).cognitoUserPoolsAuthProvider(() -> {
try {
return AWSMobileClient.getInstance().getTokens().getIdToken().toString();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build());
String expected = "ClientDatabasePrefix validation failed. The ClientDatabasePrefix ";
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 testConfigHasClientDatabasePrefixAndUseClientDatabasePrefixTrue.
@Test
public void testConfigHasClientDatabasePrefixAndUseClientDatabasePrefixTrue() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
AWSAppSyncClients.validateAppSyncClient(AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).useClientDatabasePrefix(true).build(), JsonExtract.stringValue(appSyncConfig, "ClientDatabasePrefix"), JsonExtract.stringValue(appSyncConfig, "AuthMode"));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testNoContextThrowsException.
@Test
public void testNoContextThrowsException() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build());
String expected = "A valid Android Context is required.";
assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class AWSAppSyncClients method withUserPoolsFromAWSConfiguration.
@NonNull
public static AWSAppSyncClient withUserPoolsFromAWSConfiguration() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS");
return AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).cognitoUserPoolsAuthProvider(() -> {
try {
String idToken = TestAWSMobileClient.instance(getTargetContext()).getTokens().getIdToken().getTokenString();
Log.d(TAG, "idToken = " + idToken);
return idToken;
} catch (Exception failure) {
failure.printStackTrace();
return null;
}
}).useClientDatabasePrefix(true).build();
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.
the class AWSAppSyncClients method withAPIKEYFromAWSConfiguration.
@NonNull
public static AWSAppSyncClient withAPIKEYFromAWSConfiguration(boolean subscriptionsAutoReconnect, long credentialsDelay) {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject ccpConfig = awsConfiguration.optJsonObject("CredentialsProvider");
String cognitoIdentityPoolID = JsonExtract.stringValue(ccpConfig, "CognitoIdentity.Default.PoolId");
String cognitoRegion = JsonExtract.stringValue(ccpConfig, "CognitoIdentity.Default.Region");
DelayedCognitoCredentialsProvider credentialsProvider = new DelayedCognitoCredentialsProvider(cognitoIdentityPoolID, Regions.fromName(cognitoRegion), credentialsDelay);
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider, Region.getRegion("us-west-2"));
S3ObjectManager s3ObjectManager = new S3ObjectManagerImplementation((s3Client));
return AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).conflictResolver(new TestConflictResolver()).s3ObjectManager(s3ObjectManager).subscriptionsAutoReconnect(subscriptionsAutoReconnect).mutationQueueExecutionTimeout(TimeUnit.SECONDS.toMillis(30)).persistentMutationsCallback(LoggingPersistentMutationsCallback.instance()).useClientDatabasePrefix(true).build();
}
Aggregations