Search in sources :

Example 1 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentName.

@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentName() {
    UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
    Environment env = new Environment();
    env.setParameters(new AwsParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
    EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentName(ACCOUNT_ID, ENVIRONMENT_NAME, updateAwsDiskEncryptionParametersDto);
    assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
    ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
    verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
    assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentCrn.

@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentCrn() {
    UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
    Environment env = new Environment();
    env.setParameters(new AwsParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
    EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, CRN, updateAwsDiskEncryptionParametersDto);
    assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
    ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
    verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
    assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method editByNameSecurityAccessChangeHasSecurityGroupsError.

@Test
void editByNameSecurityAccessChangeHasSecurityGroupsError() {
    ValidationResult validationResultError = ValidationResult.builder().error("sec group error").build();
    SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withCidr("test").build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withSecurityAccess(securityAccessDto).build();
    Environment value = new Environment();
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateSecurityAccessModification(any(), any())).thenReturn(validationResult);
    when(validatorService.validateSecurityGroups(any(), any())).thenReturn(validationResultError);
    BadRequestException actual = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
    assertEquals("sec group error", actual.getMessage());
    verify(environmentService, times(0)).editSecurityAccess(eq(value), eq(securityAccessDto));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test)

Example 4 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenDontDeleteOldKey.

@Test
void testEditAuthenticationIfChangedWhenDontDeleteOldKey() {
    AuthenticationDto authenticationDto = AuthenticationDto.builder().build();
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
    Environment environment = new Environment();
    EnvironmentAuthentication originalEnvironmentAuthentication = new EnvironmentAuthentication();
    originalEnvironmentAuthentication.setManagedKey(false);
    originalEnvironmentAuthentication.setPublicKeyId("old-public-key-id");
    environment.setAuthentication(originalEnvironmentAuthentication);
    EnvironmentAuthentication newEnvironmentAuthentication = new EnvironmentAuthentication();
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
    when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
    when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
    when(authenticationDtoConverter.dtoToAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
    environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
    verify(environmentResourceService, times(0)).deletePublicKey(environment, "old-public-key-id");
    verify(environmentResourceService, times(0)).createAndUpdateSshKey(environment);
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test)

Example 5 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testChangeTelemetryFeaturesByEnvironmentName.

@Test
public void testChangeTelemetryFeaturesByEnvironmentName() {
    String accountId = "myAccountId";
    String envName = "myEnvName";
    EnvironmentFeatures featuresInput = new EnvironmentFeatures();
    featuresInput.addClusterLogsCollection(true);
    Environment environment = new Environment();
    environment.setTelemetry(new EnvironmentTelemetry());
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(envName, accountId)).thenReturn(Optional.of(environment));
    when(environmentService.save(environment)).thenReturn(environment);
    when(environmentDtoConverter.environmentToDto(environment)).thenReturn(new EnvironmentDto());
    environmentModificationServiceUnderTest.changeTelemetryFeaturesByEnvironmentName(accountId, envName, featuresInput);
    verify(environmentService).save(any());
    assertTrue(environment.getTelemetry().getFeatures().getClusterLogsCollection().isEnabled());
}
Also used : EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentFeatures(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentFeatures) 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