use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider 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.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class AppSyncClientUnitTest method testMultipleAuth.
@Test(expected = RuntimeException.class)
public void testMultipleAuth() {
awsConfiguration.setConfiguration("ApiKey");
APIKeyAuthProvider apiKeyAuthProvider = new BasicAPIKeyAuthProvider(awsConfiguration);
awsConfiguration.setConfiguration("AmazonCognitoUserPools");
CognitoUserPool cognitoUserPool = new CognitoUserPool(shadowContext, awsConfiguration);
BasicCognitoUserPoolsAuthProvider basicCognitoUserPoolsAuthProvider = new BasicCognitoUserPoolsAuthProvider(cognitoUserPool);
final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).apiKey(apiKeyAuthProvider).cognitoUserPoolsAuthProvider(basicCognitoUserPoolsAuthProvider).build();
}
use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixTrue.
@Test
public void testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixTrue() {
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).build());
String expected = "Please pass in a valid ClientDatabasePrefix when useClientDatabasePrefix is true.";
assertEquals(expected, exception.getLocalizedMessage());
}
use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasNullClientDatabasePrefix.
@Test
public void testCodeHasNullClientDatabasePrefix() {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
// noinspection ConstantConditions null argument is what is is being tested
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!!
null).build());
String expected = "Please pass in a valid ClientDatabasePrefix when useClientDatabasePrefix is true.";
assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse.
@Test
public void testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse() 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).build();
AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, null, appSyncConfig.getString("AuthMode"));
}
Aggregations