use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenHasPublicKeyIdButNotExists.
@Test
void testValidateAuthenticationModificationWhenHasPublicKeyIdButNotExists() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").build()).build();
PublicKeyConnector connector = mock(PublicKeyConnector.class);
when(environmentResourceService.isPublicKeyIdExists(environment, "pub-key-id")).thenReturn(false);
when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.of(connector));
ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
assertEquals("The publicKeyId with name of 'pub-key-id' does not exist on the provider.", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenNotAwsAndHasPublicKeyId.
@Test
void testValidateAuthenticationModificationWhenNotAwsAndHasPublicKeyId() {
Environment environment = new Environment();
environment.setCloudPlatform("AZURE");
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").build()).build();
when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.empty());
ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
assertEquals("The change of publicKeyId is not supported on AZURE", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenPublicKeyAndPublicKeyIdIsEmptyAsWell.
@Test
void testValidateAuthenticationModificationWhenPublicKeyAndPublicKeyIdIsEmptyAsWell() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().build()).build();
ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
assertEquals("You should define either the publicKey or the publicKeyId.", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell.
@Test
void testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell() {
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").withPublicKey("ssh-key").build()).build();
PublicKeyConnector connector = mock(PublicKeyConnector.class);
when(environmentResourceService.isPublicKeyIdExists(environment, "pub-key-id")).thenReturn(true);
when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.of(connector));
when(publicKeyValidator.validatePublicKey(anyString())).thenReturn(ValidationResult.empty());
ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
assertEquals("You should define either publicKey or publicKeyId only, but not both.", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentController method editByName.
@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.EDIT_ENVIRONMENT)
public DetailedEnvironmentResponse editByName(@ResourceName String environmentName, @NotNull EnvironmentEditRequest request) {
EnvironmentEditDto editDto = environmentApiConverter.initEditDto(request);
EnvironmentDto result = environmentModificationService.editByName(environmentName, editDto);
return environmentResponseConverter.dtoToDetailedResponse(result);
}
Aggregations