use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto 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.dto.EnvironmentEditDto 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.dto.EnvironmentEditDto 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.dto.EnvironmentEditDto 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.dto.EnvironmentEditDto 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