Search in sources :

Example 91 with Environment

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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with Environment

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);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 93 with Environment

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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) Test(org.junit.jupiter.api.Test)

Example 94 with Environment

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);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 95 with 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);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10