use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class NetworkServiceTest method testMergeNetworkDtoWithNetworkIfNetworkCreateNew.
// TODO: 2020. 01. 31. move these tests to the new CloudNetworkServiceTest class
/*@Test
public void testRetrieveSubnetMetadataIfNetworkNull() {
Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(null, null);
Assertions.assertTrue(actual.isEmpty());
}
@Test
public void testRetrieveSubnetMetadataWhenAwsAndNoExistedSubnetOnProvider() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
Region region = new Region();
region.setName("region1");
environment.setRegions(Set.of(region));
NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", new CloudSubnet())).build();
when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1", Set.of())));
Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
Assertions.assertTrue(actual.isEmpty());
}
@Test
public void testRetrieveSubnetMetadataWhenAwsAndHasSubnetOnProviderAndMatch() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
Region region = new Region();
region.setName("region1");
environment.setRegions(Set.of(region));
CloudSubnet editSubnet = new CloudSubnet();
NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", editSubnet)).build();
CloudSubnet providerSubnet = new CloudSubnet();
providerSubnet.setId("sub");
CloudNetwork cloudNetwork = new CloudNetwork("network", "network", Set.of(providerSubnet), Collections.emptyMap());
when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1",
Set.of(cloudNetwork))));
Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
Assertions.assertEquals(1, actual.size());
Assertions.assertEquals(actual.get("sub"), providerSubnet);
}
@Test
public void testRetrieveSubnetMetadataWhenAwsAndHasSubnetOnProviderAndNotMatch() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
Region region = new Region();
region.setName("region1");
environment.setRegions(Set.of(region));
CloudSubnet editSubnet = new CloudSubnet();
NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", editSubnet)).build();
CloudSubnet providerSubnet = new CloudSubnet();
providerSubnet.setId("diff-sub");
CloudNetwork cloudNetwork = new CloudNetwork("network", "network", Set.of(providerSubnet), Collections.emptyMap());
when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1",
Set.of(cloudNetwork))));
Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
Assertions.assertEquals(0, actual.size());
}*/
@ParameterizedTest
@EnumSource(CloudPlatform.class)
public void testMergeNetworkDtoWithNetworkIfNetworkCreateNew(CloudPlatform cloudPlatform) {
AwsNetwork baseNetwork = new AwsNetwork();
baseNetwork.setSubnetMetas(Collections.emptyMap());
baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
Environment environment = new Environment();
environment.setCloudPlatform(cloudPlatform.name());
environment.setNetwork(baseNetwork);
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
when(environmentNetworkConverterMap.get(cloudPlatform)).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(networkCreationValidator.validateNetworkEdit(eq(environment), any(NetworkDto.class))).thenReturn(new ValidationResult.ValidationResultBuilder());
BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.validate(baseNetwork, environmentEditDto, environment));
String baseMessage = "Subnets of this environment could not be modified, because its network has been created by Cloudera. " + "You need to re-install the environment into an existing VPC/VNet.";
String providerSpecificLink = "";
switch(cloudPlatform) {
case AWS:
providerSpecificLink = " Refer to Cloudera documentation at " + "https://docs.cloudera.com/management-console/cloud/environments/topics/mc-subnet-adding-azure.html for more information.";
break;
case AZURE:
providerSpecificLink = " Refer to Cloudera documentation at " + "https://docs.cloudera.com/management-console/cloud/environments-azure/topics/mc-subnet-adding-azure.html for more information.";
break;
default:
break;
}
Assertions.assertEquals(String.format("%s%s", baseMessage, providerSpecificLink), exception.getMessage());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.
@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("GCP");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class AwsEnvironmentNetworkConverterTest method createEnvironment.
private Environment createEnvironment() {
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setId(1L);
environment.setAccountId("2");
environment.setDescription("description");
environment.setCloudPlatform("AWS");
environment.setCredential(new Credential());
environment.setLatitude(2.4);
environment.setLongitude(3.5);
environment.setLocation(LOCATION);
environment.setLocationDisplayName("London");
environment.setNetwork(new AwsNetwork());
environment.setRegions(Collections.singleton(new Region()));
return environment;
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class AwsEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent.
@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent() {
Environment environment = createEnvironment();
NetworkDto networkDto = NetworkDto.builder().withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
AwsNetwork actual = (AwsNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
assertEquals(environment.getName(), actual.getName());
assertNull(actual.getVpcId());
assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
assertEquals(RegistrationType.CREATE_NEW, 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 EnvironmentValidatorServiceTest method shouldNotFailInCaseOfVaildParentChildEnvironment.
@Test
void shouldNotFailInCaseOfVaildParentChildEnvironment() {
Environment environment = aValidEnvirontmentWithParent();
ValidationResult validationResult = underTest.validateParentChildRelation(environment, "parentEnvName");
assertFalse(validationResult.hasError());
}
Aggregations