@Test
    public void getCredentialsDisabled_shouldGetCredentialsAfterEnabled() throws Exception {
        InstanceProfileCredentialsProvider credentialsProvider = null;
        try {
            System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true");
            credentialsProvider = new InstanceProfileCredentialsProvider();
            credentialsProvider.getCredentials();
            fail("exception not thrown when ec2Metadata disabled");
        } catch (AmazonClientException ex) {
            //expected
        } finally {
            System.clearProperty("com.amazonaws.sdk.disableEc2Metadata");
        }
        mockServer.setResponseContent(nonExpiredResponse());
        mockServer.setAvailableSecurityCredentials("test-credentials");
        assertNotNull(credentialsProvider.getCredentials());
    }
Tests that we correctly handle when no instance profiles are available
through the metadata service.
aws-java-sdk-core/src/test/java/com/amazonaws/auth/InstanceProfileCredentialsProviderIntegrationTest.java