use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameAuthenticationChange.
@Test
void editByNameAuthenticationChange() {
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).build();
Environment value = new Environment();
EnvironmentDto environmentDto = new EnvironmentDto();
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
when(environmentDtoConverter.environmentToDto(value)).thenReturn(environmentDto);
when(environmentService.save(value)).thenReturn(value);
EnvironmentDto actual = environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentEditDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
assertEquals(actual, environmentDto);
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails.
@Test
void testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails() {
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
BaseParameters baseParameters = new GcpParameters();
baseParameters.setId(123L);
ValidationResult validationResultError = ValidationResult.builder().error("Wrong key format").build();
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(validationResultError);
when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
verify(parametersService, never()).saveParameters(environment, parameters);
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNeedToCreateSshKey.
@Test
void testEditAuthenticationIfChangedWhenNeedToCreateSshKey() {
AuthenticationDto authenticationDto = AuthenticationDto.builder().withPublicKey("ssh-key").build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
Environment environment = new Environment();
EnvironmentAuthentication originalEnvironmentAuthentication = new EnvironmentAuthentication();
originalEnvironmentAuthentication.setPublicKey("original-ssh-key");
originalEnvironmentAuthentication.setManagedKey(false);
environment.setAuthentication(originalEnvironmentAuthentication);
EnvironmentAuthentication newEnvironmentAuthentication = new EnvironmentAuthentication();
newEnvironmentAuthentication.setPublicKey("new-ssh-key");
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
when(authenticationDtoConverter.dtoToAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
when(environmentResourceService.createAndUpdateSshKey(environment)).thenReturn(true);
environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
verify(environmentResourceService, times(1)).createAndUpdateSshKey(environment);
verify(environmentResourceService, times(0)).deletePublicKey(environment, "old-public-key-id");
assertEquals(environment.getAuthentication().getPublicKey(), "new-ssh-key");
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByName.
@Test
void editByName() {
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).build();
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment()));
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
verify(environmentService).save(any());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersNotExisted.
@Test
void editByNameParametersNotExisted() {
String dynamotable = "dynamotable";
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(dynamotable).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
BaseParameters baseParameters = new AwsParameters();
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
verify(parametersService).saveParameters(environment, parameters);
assertEquals(baseParameters, environment.getParameters());
}
Aggregations