use of com.kixeye.chassis.bootstrap.aws.ServerInstanceContext in project chassis by Kixeye.
the class ConfigurationBuilderTest method buildConfigurationInAws.
@Test
public void buildConfigurationInAws() {
String az = "testaz";
String instanceId = RandomStringUtils.randomAlphabetic(10);
String region = Regions.DEFAULT_REGION.getName();
ServerInstanceContext serverInstanceContext = EasyMock.createMock(ServerInstanceContext.class);
EasyMock.expect(serverInstanceContext.getAvailabilityZone()).andReturn(az);
EasyMock.expect(serverInstanceContext.getInstanceId()).andReturn(instanceId);
EasyMock.expect(serverInstanceContext.getRegion()).andReturn(region);
EasyMock.expect(serverInstanceContext.getPrivateIp()).andReturn("127.0.0.1");
EasyMock.expect(serverInstanceContext.getPublicIp()).andReturn(null);
EasyMock.replay(serverInstanceContext);
Configuration configuration = configurationBuilder.withServerInstanceContext(serverInstanceContext).build();
Assert.assertEquals(az, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName()));
Assert.assertEquals(instanceId, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName()));
Assert.assertEquals(region, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName()));
Assert.assertEquals("127.0.0.1", configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PRIVATE_IP.getPropertyName()));
Assert.assertEquals(null, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PUBLIC_IP.getPropertyName()));
EasyMock.verify(serverInstanceContext);
}
use of com.kixeye.chassis.bootstrap.aws.ServerInstanceContext in project chassis by Kixeye.
the class BootstrapConfiguration method applicationConfiguration.
@Bean
@SuppressWarnings("resource")
public AbstractConfiguration applicationConfiguration() throws ClassNotFoundException {
AppMetadata appMetadata = appMetadata();
ServerInstanceContext serverInstanceContext = serverInstanceContext();
if (appEnvironment == null && serverInstanceContext != null) {
appEnvironment = serverInstanceContext.getEnvironment();
}
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(appMetadata.getName(), appEnvironment, addSystemConfigs, reflections());
configurationBuilder.withConfigurationProvider(configurationProvider());
configurationBuilder.withServerInstanceContext(serverInstanceContext());
configurationBuilder.withApplicationProperties(appMetadata.getPropertiesResourceLocation());
configurationBuilder.withScanModuleConfigurations(scanModuleConfigurations);
configurationBuilder.withAppVersion(appMetadata.getDeclaringClass().getPackage().getImplementationVersion());
AbstractConfiguration configuration = configurationBuilder.build();
if (serverInstanceContext != null) {
serverInstanceContext.setAppName(appMetadata.getName());
serverInstanceContext.setVersion(configuration.getString(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName()));
}
return configuration;
}
Aggregations