Search in sources :

Example 6 with BasicAPIKeyAuthProvider

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));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 7 with BasicAPIKeyAuthProvider

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();
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) BasicCognitoUserPoolsAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider) APIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 8 with BasicAPIKeyAuthProvider

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());
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 9 with BasicAPIKeyAuthProvider

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));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 10 with BasicAPIKeyAuthProvider

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"));
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Aggregations

BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)11 Test (org.junit.Test)11 AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)9 JSONObject (org.json.JSONObject)9 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)3 APIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider)2 BasicCognitoUserPoolsAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider)2 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)2 AWSAppSyncClientException (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClientException)1 ClearCacheException (com.amazonaws.mobileconnectors.appsync.ClearCacheException)1 JSONException (org.json.JSONException)1