use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameAwsFreeIpaSpotPercentageIsNotModified.
@Test
void editByNameAwsFreeIpaSpotPercentageIsNotModified() {
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withFreeIpaSpotPercentage(50).build()).build()).build();
Environment value = new Environment();
AwsParameters awsParameters = new AwsParameters();
int originalFreeIpaSpotPercentage = 100;
awsParameters.setFreeIpaSpotPercentage(originalFreeIpaSpotPercentage);
value.setParameters(awsParameters);
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
Environment result = environmentArgumentCaptor.getValue();
AwsParameters newAwsParameters = (AwsParameters) result.getParameters();
assertEquals(originalFreeIpaSpotPercentage, newAwsParameters.getFreeIpaSpotPercentage());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersErrorsWhenEncryptionKeyAlreadyPresent.
@Test
void testUpdateAzureResourceEncryptionParametersErrorsWhenEncryptionKeyAlreadyPresent() {
UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
Environment env = new Environment();
AzureParameters azureParameters = new AzureParameters();
azureParameters.setEncryptionKeyUrl("dummyEncryptionKey");
env.setParameters(azureParameters);
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto));
assertEquals(badRequestException.getMessage(), String.format("Encryption Key '%s' is already set for the environment '%s'. " + "Modifying the encryption key is not allowed.", "dummyEncryptionKey", ENVIRONMENT_NAME));
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersNoErrorWhenSameEncryptionKeyAlreadyPresent.
@Test
void testUpdateAzureResourceEncryptionParametersNoErrorWhenSameEncryptionKeyAlreadyPresent() {
UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
Environment env = new Environment();
AzureParameters azureParameters = new AzureParameters();
azureParameters.setEncryptionKeyUrl("dummyKeyUrl");
env.setParameters(azureParameters);
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
when(validatorService.validateEncryptionKeyUrl(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
when(environmentDtoConverter.environmentToDto(env)).thenReturn(new EnvironmentDto());
environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto);
verify(environmentDtoConverter, times(1)).environmentToDto(env);
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByCrn.
@Test
void editByCrn() {
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).build();
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment()));
environmentModificationServiceUnderTest.editByCrn(CRN, environmentDto);
verify(environmentService).save(any());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenHasValidationError.
@Test
void testEditAuthenticationIfChangedWhenHasValidationError() {
AuthenticationDto authenticationDto = AuthenticationDto.builder().build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
Environment environment = new Environment();
ValidationResult validationResult = ValidationResult.builder().error("Error").build();
when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment));
assertEquals(badRequestException.getMessage(), "Error");
}
Aggregations