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());
}
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());
}
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));
}
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);
}
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());
}
Aggregations