AmazonConfigurationLoader { public Map<String, AWSInstanceProfile> getConfiguredProfiles() { List<Object> profilesList = configuration.getList(PROFILES, Collections.EMPTY_LIST); Map<String, Map<String, String>> profileSpecifications = ConfigurationUtil.reduceObjectList(profilesList, "Profiles must be specified as a list of objects."); SortedMap<String, AWSInstanceProfile> profiles = Maps.newTreeMap(); for (Map.Entry<String, Map<String, String>> entry : profileSpecifications.entrySet()) { String profileName = entry.getKey(); Map<String, String> profileValues = entry.getValue(); AWSInstanceProfile profile = AWSInstanceProfile.newBuilder(). profileName(profileName). region(profileValues.get(REGION)). zone(profileValues.get(ZONE)). type(profileValues.get(TYPE)). amiId(profileValues.get(AMI_ID)). keypairName(profileValues.get(KEYPAIR)). shutdownState(profileValues.get(SHUTDOWN_STATE)). group(profileValues.get(GROUP)). spotPrice(profileValues.get(SPOT_PRICE)). spotRequestType(profileValues.get(SPOT_REQUEST_TYPE)). spotRequestValidFrom(profileValues.get(SPOT_REQUEST_VALID_FROM)). spotRequestValidTo(profileValues.get(SPOT_REQUEST_VALID_TO)). placementGroup(profileValues.get(PLACEMENT_GROUP)). build(); profiles.put(profileName, profile); } return profiles; } AmazonConfigurationLoader(Configuration configuration); String getAccessKeyId(); String getSecretKey(); String getNodeJvmOptions(); LogLevel getNodeLogLevel(); Boolean getNodeRemoteLogging(); Integer getNodeRemoteLoggingPort(); Set<Credentials> getConfiguredCredentials(); Map<String, AWSInstanceProfile> getConfiguredProfiles(); static final String ACCESS_KEY_ID; static final String SECRET_KEY; static final String KEYPAIRS; static final String PROFILES; static final String PRIVATE_KEY; static final String PUBLIC_KEY; static final String USER; static final String AMI_ID; static final String REGION; static final String ZONE; static final String TYPE; static final String KEYPAIR; static final String SHUTDOWN_STATE; static final String GROUP; static final String SPOT_PRICE; static final String SPOT_REQUEST_TYPE; static final String SPOT_REQUEST_VALID_FROM; static final String SPOT_REQUEST_VALID_TO; static final String PLACEMENT_GROUP; static final String NODE_JVM_OPTIONS; static final String NODE_LOG_LEVEL; static final String NODE_LOG_REMOTE; static final String NODE_LOG_REMOTE_PORT; }
@Test public void testGetConfiguredProfiles() throws ConfigurationException, ParseException { goodConfigSetup(); Map<String, AWSInstanceProfile> result = configLoader.getConfiguredProfiles(); assertThat(result, allOf( Matchers.<String, AWSInstanceProfile>hasKey(PROFILE1), Matchers.<String, AWSInstanceProfile>hasKey(PROFILE2) )); assertThat(result.get(PROFILE1).getAmiId().get(), is(equalTo(AMI_ID1))); assertThat(result.get(PROFILE1).getRegion(), is(equalTo(REGION1))); assertThat(result.get(PROFILE1).getType(), is(equalTo(TYPE1))); assertThat(result.get(PROFILE1).getZone().get(), is(equalTo(ZONE1))); assertThat(result.get(PROFILE1).getKeyPairName().get(), is(equalTo(KEYPAIR1))); assertThat(result.get(PROFILE1).getShutdownState().get(), is(equalTo(SHUTDOWN_STATE1))); assertThat(result.get(PROFILE1).getSpotPrice().get(), is(equalTo(Float.parseFloat(SPOT_PRICE)))); assertThat(result.get(PROFILE1).getSpotRequestType().get(), is(equalTo(SPOT_REQUEST_TYPE))); assertThat(result.get(PROFILE1).getGroup().get(), is(equalTo(GROUP))); assertThat(result.get(PROFILE1).getPlacementGroup().get(), is(equalTo(PLACEMENT_GROUP))); assertThat(result.get(PROFILE1).getSpotRequestValidFrom().get(), is(equalTo(simpleDateFormat.parse(SPOT_REQUEST_VALID_FROM)))); assertThat(result.get(PROFILE1).getSpotRequestValidTo().get(), is(equalTo(simpleDateFormat.parse(SPOT_REQUEST_VALID_TO)))); assertThat(result.get(PROFILE2).getAmiId().get(), is(equalTo(AMI_ID2))); assertThat(result.get(PROFILE2).getRegion(), is(equalTo(REGION2))); assertThat(result.get(PROFILE2).getType(), is(equalTo(TYPE2))); assertThat(result.get(PROFILE2).getZone().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getKeyPairName().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getShutdownState().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getSpotPrice().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getSpotRequestType().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getGroup().isPresent(), is(equalTo(false))); assertThat(result.get(PROFILE2).getPlacementGroup().isPresent(), is(equalTo(false))); }
@Test(expected=NullPointerException.class) public void testGetBadConfiguredProfiles() throws ConfigurationException { badConfigSetup(); configLoader.getConfiguredProfiles(); }