use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs.
@Test
public void testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs() {
String primaryCidr = "10.0.0.0/16";
String secondaryCidr = "10.2.0.0/16";
AwsNetwork baseNetwork = new AwsNetwork();
baseNetwork.setSubnetMetas(Collections.emptyMap());
baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
environment.setNetwork(baseNetwork);
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
Network network = new Network(new Subnet(primaryCidr));
NetworkCidr networkCidr = new NetworkCidr(primaryCidr, List.of(primaryCidr, secondaryCidr));
when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(environmentNetworkConverter.convertToNetwork(baseNetwork)).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential())).thenReturn(networkCidr);
BaseNetwork actualNetwork = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
verify(cloudNetworkService, times(1)).retrieveSubnetMetadata(eq(environment), any(NetworkDto.class));
verify(environmentNetworkService, times(1)).getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
Assertions.assertEquals(primaryCidr, actualNetwork.getNetworkCidr());
Assertions.assertEquals(StringUtils.join(networkCidr.getCidrs(), ","), actualNetwork.getNetworkCidrs());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class ParametersServiceTest method saveParameters.
@Test
void saveParameters() {
AwsParameters awsParameters = new AwsParameters();
when(environmentParamsConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentParametersConverter);
when(environmentParametersConverter.convert(any(Environment.class), any(ParametersDto.class))).thenReturn(awsParameters);
when(baseParametersRepository.save(any())).thenReturn(awsParameters);
Environment environment = new Environment();
environment.setAccountId("accountId");
environment.setCloudPlatform("AWS");
BaseParameters result = underTest.saveParameters(environment, ParametersDto.builder().build());
assertEquals(awsParameters, result);
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class GcpEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey(ENCRYPTION_KEY).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(GcpParameters.class, result.getClass());
GcpParameters gcpResult = (GcpParameters) result;
assertEquals(ENV_NAME, gcpResult.getName());
assertEquals(ACCOUNT_ID, gcpResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, gcpResult.getEnvironment());
assertEquals(ID, gcpResult.getId());
assertEquals(ENCRYPTION_KEY, gcpResult.getEncryptionKey());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class AwsEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto.
@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto() {
Environment environment = createEnvironment();
NetworkDto networkDto = NetworkDto.builder().withAws(AwsParams.builder().withVpcId(VPC_ID).build()).withName(NETWORK_NAME).withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
AwsNetwork actual = (AwsNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
assertEquals(NETWORK_NAME, actual.getName());
assertEquals(VPC_ID, actual.getVpcId());
assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
assertEquals(RegistrationType.EXISTING, actual.getRegistrationType());
assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
verify(environmentViewConverter).convert(environment);
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent.
@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent() {
Environment environment = createEnvironment();
NetworkDto networkDto = NetworkDto.builder().withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
AzureNetwork actual = (AzureNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
assertEquals(environment.getName(), actual.getName());
assertNull(actual.getNetworkId());
assertNull(actual.getResourceGroupName());
assertFalse(actual.getNoPublicIp());
assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
assertEquals(RegistrationType.CREATE_NEW, actual.getRegistrationType());
assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
verify(environmentViewConverter).convert(environment);
}
Aggregations