Search in sources :

Example 16 with AWSConfiguration

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

the class AWSMobileClientNetworkIssueTest method testGetConfiguration.

@Test
public void testGetConfiguration() {
    final AWSConfiguration awsConfiguration = AWSMobileClient.getInstance().getConfiguration();
    assertNotNull(awsConfiguration.optJsonObject("CognitoUserPool"));
    try {
        assertEquals("us-west-2", awsConfiguration.optJsonObject("CognitoUserPool").getString("Region"));
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JSONException(org.json.JSONException) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 17 with AWSConfiguration

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

the class AWSMobileClientOfflineTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws JSONException {
    AWSConfiguration awsConfiguration = auth.getConfiguration();
    JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
    assertNotNull(userPoolConfig);
    assertEquals("us-west-2", userPoolConfig.getString("Region"));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 18 with AWSConfiguration

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

the class AWSMobileClientAuthFlowSettingTest method initMobileClientAndWait.

private void initMobileClientAndWait(String authFlowType, CognitoUserPool mockUserPool) throws JSONException, InterruptedException {
    JSONObject awsConfig = getAWSConfig(authFlowType);
    mobileClient.initialize(getApplicationContext(), new AWSConfiguration(awsConfig), new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            mobileClient.setUserPool(mockUserPool);
            Log.i(TAG, "Mobile client initialized. Mock user pool injected.");
            initComplete.set(true);
            initLatch.countDown();
        }

        @Override
        public void onError(Exception exception) {
            Log.e(TAG, "Mobile client failed to initialize.", exception);
            initLatch.countDown();
        }
    });
    initLatch.await(5, TimeUnit.SECONDS);
    assertTrue(initComplete.get());
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) JSONException(org.json.JSONException)

Example 19 with AWSConfiguration

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

the class TransferUtilityTest method testLocalTestingUnset.

/**
 * Tests that transfer utility correctly ignored local testing branch
 * if local testing flag is not specified.
 *
 * @throws Exception
 */
@Test
public void testLocalTestingUnset() throws Exception {
    final String jsonString = "{\n" + "  \"S3TransferUtility\": {\n" + "    \"Default\": {\n" + "      \"Bucket\": \"name\",\n" + "      \"Region\": \"us-east-1\"\n" + "    }\n" + "  }\n" + "}";
    try {
        JSONObject jsonConfig = new JSONObject(jsonString);
        awsConfig = new AWSConfiguration(jsonConfig);
    } catch (JSONException e) {
        fail("Error in constructing AWSConfiguration." + e.getLocalizedMessage());
    }
    AWSCredentials creds = new BasicAWSCredentials("accessKey", "secretKey");
    Region region = Region.getRegion(Regions.DEFAULT_REGION);
    AmazonS3Client s3 = new AmazonS3Client(creds, region);
    TransferUtility.builder().context(RuntimeEnvironment.application.getApplicationContext()).awsConfiguration(awsConfig).s3Client(s3).build();
    assertNotEquals(s3.getEndpoint(), Constants.LOCAL_TESTING_ENDPOINT);
    assertFalse(s3.clientOptions.isPathStyleAccess());
    assertFalse(s3.clientOptions.isContentMd5CheckSkipped());
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Region(com.amazonaws.regions.Region) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Test(org.junit.Test)

Example 20 with AWSConfiguration

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

the class TransferUtilityTest method testLocalTestingDisabled.

/**
 * Tests that transfer utility correctly ignored local testing branch
 * if local testing flag is set to false.
 *
 * @throws Exception
 */
@Test
public void testLocalTestingDisabled() throws Exception {
    final String jsonString = "{\n" + "  \"S3TransferUtility\": {\n" + "    \"Default\": {\n" + "      \"Bucket\": \"name\",\n" + "      \"Region\": \"us-east-1\",\n" + "      \"DangerouslyConnectToHTTPEndpointForTesting\": false\n" + "    }\n" + "  }\n" + "}";
    try {
        JSONObject jsonConfig = new JSONObject(jsonString);
        awsConfig = new AWSConfiguration(jsonConfig);
    } catch (JSONException e) {
        fail("Error in constructing AWSConfiguration." + e.getLocalizedMessage());
    }
    AWSCredentials creds = new BasicAWSCredentials("accessKey", "secretKey");
    Region region = Region.getRegion(Regions.DEFAULT_REGION);
    AmazonS3Client s3 = new AmazonS3Client(creds, region);
    TransferUtility.builder().context(RuntimeEnvironment.application.getApplicationContext()).awsConfiguration(awsConfig).s3Client(s3).build();
    assertNotEquals(s3.getEndpoint(), Constants.LOCAL_TESTING_ENDPOINT);
    assertFalse(s3.clientOptions.isPathStyleAccess());
    assertFalse(s3.clientOptions.isContentMd5CheckSkipped());
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Region(com.amazonaws.regions.Region) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) 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