Search in sources :

Example 26 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.

the class AWSMobileClientNetworkIssueTest method useAppContext.

@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = ApplicationProvider.getApplicationContext();
    final AWSConfiguration awsConfiguration = new AWSConfiguration(appContext);
    assertNotNull(awsConfiguration.optJsonObject("CognitoUserPool"));
    assertEquals("us-west-2", awsConfiguration.optJsonObject("CognitoUserPool").getString("Region"));
    assertEquals("com.amazonaws.mobile.client.test", appContext.getPackageName());
}
Also used : Context(android.content.Context) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 27 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.

the class AWSMobileClientNetworkIssueTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    Context appContext = ApplicationProvider.getApplicationContext();
    // Initialize
    final CountDownLatch latch = new CountDownLatch(1);
    AWSMobileClient.getInstance().initialize(appContext, new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            latch.countDown();
        }

        @Override
        public void onError(Exception e) {
            latch.countDown();
        }
    });
    latch.await();
    final AWSConfiguration awsConfiguration = new AWSConfiguration(appContext);
    JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
    assertNotNull(userPoolConfig);
    JSONObject identityPoolConfig = awsConfiguration.optJsonObject("CredentialsProvider").getJSONObject("CognitoIdentity").getJSONObject("Default");
    assertNotNull(identityPoolConfig);
}
Also used : Context(android.content.Context) JSONObject(org.json.JSONObject) CountDownLatch(java.util.concurrent.CountDownLatch) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) JSONException(org.json.JSONException) AmazonServiceException(com.amazonaws.AmazonServiceException) UnknownHostException(java.net.UnknownHostException) AmazonClientException(com.amazonaws.AmazonClientException) BeforeClass(org.junit.BeforeClass)

Example 28 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.

the class AWSMobileClientOfflineTest method beforeSuite.

@BeforeClass
public static void beforeSuite() throws Exception {
    goOffline();
    CountDownLatch latch = new CountDownLatch(1);
    auth = AWSMobileClient.getInstance();
    AWSConfiguration config = new AWSConfiguration(getApplicationContext(), R.raw.fakeawsconfiguration);
    auth.initialize(getApplicationContext(), config, new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            latch.countDown();
        }

        @Override
        public void onError(Exception e) {
            latch.countDown();
        }
    });
    latch.await();
    AWSConfiguration awsConfiguration = auth.getConfiguration();
    JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
    assertNotNull(userPoolConfig);
    assertEquals("us-west-2", userPoolConfig.getString("Region"));
}
Also used : JSONObject(org.json.JSONObject) CountDownLatch(java.util.concurrent.CountDownLatch) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) JSONException(org.json.JSONException) BeforeClass(org.junit.BeforeClass)

Example 29 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.

the class AWSMobileClientOfflineTest method useAppContext.

@Test
public void useAppContext() throws JSONException {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getApplicationContext(), R.raw.fakeawsconfiguration);
    JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
    assertNotNull(userPoolConfig);
    assertEquals("us-west-2", userPoolConfig.getString("Region"));
    assertEquals("com.amazonaws.mobile.client.test", getApplicationContext().getPackageName());
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 30 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    setUpCredentials();
    Context appContext = ApplicationProvider.getApplicationContext();
    final CountDownLatch latch = new CountDownLatch(1);
    AWSMobileClient.getInstance().initialize(appContext, new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            latch.countDown();
        }

        @Override
        public void onError(Exception e) {
            latch.countDown();
        }
    });
    latch.await();
    final AWSConfiguration awsConfiguration = AWSMobileClient.getInstance().getConfiguration();
    JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
    assertNotNull(userPoolConfig);
    clientRegion = Regions.fromName(userPoolConfig.getString("Region"));
    userPoolId = userPoolConfig.getString("PoolId");
    JSONObject identityPoolConfig = awsConfiguration.optJsonObject("CredentialsProvider").getJSONObject("CognitoIdentity").getJSONObject("Default");
    assertNotNull(identityPoolConfig);
    deleteAllUsers(userPoolId);
}
Also used : Context(android.content.Context) JSONObject(org.json.JSONObject) CountDownLatch(java.util.concurrent.CountDownLatch) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) BeforeClass(org.junit.BeforeClass)

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