CloudStore { void initializeAwsSupport() { if (!awsEnabled) { return; } if (!loadBootMetaData()) { throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR, "Unable to load boot data"); } if (!fetchRoleCredentials()) { throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR, "Unable to fetch aws role credentials"); } int credsUpdateTime = ConfigProperties.retrieveConfigSetting( ZTSConsts.ZTS_PROP_AWS_CREDS_UPDATE_TIMEOUT, 900); scheduledThreadPool = Executors.newScheduledThreadPool(1); scheduledThreadPool.scheduleAtFixedRate(new AWSCredentialsUpdater(), credsUpdateTime, credsUpdateTime, TimeUnit.SECONDS); } CloudStore(); void close(); void setHttpClient(HttpClient client); boolean isAwsEnabled(); AmazonS3 getS3Client(); AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal,
                                                 Integer durationSeconds, String externalId); String getCloudAccount(String domainName);  }
@Test public void testInitializeAwsSupport() throws ExecutionException, TimeoutException { CloudStore store = new CloudStore(); HttpClient httpClient = Mockito.mock(HttpClient.class); ContentResponse responseDoc = Mockito.mock(ContentResponse.class); Mockito.when(responseDoc.getStatus()).thenReturn(200); Mockito.when(responseDoc.getContentAsString()).thenReturn(AWS_INSTANCE_DOCUMENT); ContentResponse responseSig = Mockito.mock(ContentResponse.class); Mockito.when(responseSig.getStatus()).thenReturn(200); Mockito.when(responseSig.getContentAsString()).thenReturn("pkcs7-signature"); ContentResponse responseInfo = Mockito.mock(ContentResponse.class); Mockito.when(responseInfo.getStatus()).thenReturn(200); Mockito.when(responseInfo.getContentAsString()).thenReturn(AWS_IAM_ROLE_INFO); ContentResponse responseCreds = Mockito.mock(ContentResponse.class); Mockito.when(responseCreds.getStatus()).thenReturn(200); Mockito.when(responseCreds.getContentAsString()).thenReturn("{\"AccessKeyId\":\"id\",\"SecretAccessKey\":\"key\",\"Token\":\"token\"}"); store.setHttpClient(httpClient); try { Mockito.when(httpClient.GET("http: } catch (InterruptedException ignored) { } try { Mockito.when(httpClient.GET("http: } catch (InterruptedException ignored) { } try { Mockito.when(httpClient.GET("http: } catch (InterruptedException ignored) { } try { Mockito.when(httpClient.GET("http: } catch (InterruptedException ignored) { } System.setProperty(ZTSConsts.ZTS_PROP_AWS_CREDS_UPDATE_TIMEOUT, "1"); store.awsEnabled = true; store.initializeAwsSupport(); try { Thread.sleep(2000); } catch (InterruptedException ignored) { } store.close(); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_CREDS_UPDATE_TIMEOUT); }