Search in sources :

Example 1 with AWSConfiguration

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);
}
Also used : Context(android.content.Context) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) ApolloClient(com.apollographql.apollo.ApolloClient) RealAppSyncCall(com.apollographql.apollo.internal.RealAppSyncCall) ByteArrayInputStream(java.io.ByteArrayInputStream) SubscriptionManager(com.apollographql.apollo.internal.subscription.SubscriptionManager) Resources(android.content.res.Resources) Subscription(com.apollographql.apollo.api.Subscription) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Before(org.junit.Before)

Example 2 with AWSConfiguration

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

Example 3 with AWSConfiguration

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

Example 4 with AWSConfiguration

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"));
}
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)

Example 5 with AWSConfiguration

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);
}
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

AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)48 JSONObject (org.json.JSONObject)28 Test (org.junit.Test)26 JSONException (org.json.JSONException)16 Context (android.content.Context)13 NonNull (androidx.annotation.NonNull)11 BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 BeforeClass (org.junit.BeforeClass)7 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)6 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 SignInResult (com.amazonaws.mobile.client.results.SignInResult)3 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)3 UserNotConfirmedException (com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)3 Nullable (androidx.annotation.Nullable)2 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)2 AWSMobileClient (com.amazonaws.mobile.client.AWSMobileClient)2 Callback (com.amazonaws.mobile.client.Callback)2