@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("1. sec group error", actual.getMessage()); verify(environmentService, times(0)).editSecurityAccess(eq(value), eq(securityAccessDto)); }
public EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto) { Environment env = environmentService .findByNameAndAccountIdAndArchivedIsFalse(environmentName, editDto.getAccountId()) .orElseThrow(() -> new NotFoundException(String.format("No environment found with name '%s'", environmentName))); return edit(editDto, env); }
EnvironmentModificationService { public EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto) { Environment env = environmentService .findByNameAndAccountIdAndArchivedIsFalse(environmentName, editDto.getAccountId()) .orElseThrow(() -> new NotFoundException(String.format("No environment found with name '%s'", environmentName))); return edit(editDto, env); } }
EnvironmentModificationService { public EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto) { Environment env = environmentService .findByNameAndAccountIdAndArchivedIsFalse(environmentName, editDto.getAccountId()) .orElseThrow(() -> new NotFoundException(String.format("No environment found with name '%s'", environmentName))); return edit(editDto, env); } EnvironmentModificationService(EnvironmentDtoConverter environmentDtoConverter, EnvironmentService environmentService,
            CredentialService credentialService, NetworkService networkService, AuthenticationDtoConverter authenticationDtoConverter,
            ParametersService parametersService, EnvironmentFlowValidatorService environmentFlowValidatorService,
            EnvironmentResourceService environmentResourceService); }
EnvironmentModificationService { public EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto) { Environment env = environmentService .findByNameAndAccountIdAndArchivedIsFalse(environmentName, editDto.getAccountId()) .orElseThrow(() -> new NotFoundException(String.format("No environment found with name '%s'", environmentName))); return edit(editDto, env); } EnvironmentModificationService(EnvironmentDtoConverter environmentDtoConverter, EnvironmentService environmentService,
            CredentialService credentialService, NetworkService networkService, AuthenticationDtoConverter authenticationDtoConverter,
            ParametersService parametersService, EnvironmentFlowValidatorService environmentFlowValidatorService,
            EnvironmentResourceService environmentResourceService); EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto); EnvironmentDto editByCrn(String crn, EnvironmentEditDto editDto); EnvironmentDto changeCredentialByEnvironmentName(String accountId, String environmentName, EnvironmentChangeCredentialDto dto); EnvironmentDto changeCredentialByEnvironmentCrn(String accountId, String crn, EnvironmentChangeCredentialDto dto); EnvironmentDto changeTelemetryFeaturesByEnvironmentName(String accountId, String environmentName,
            EnvironmentFeatures features); EnvironmentDto changeTelemetryFeaturesByEnvironmentCrn(String accountId, String crn,
            EnvironmentFeatures features); }
EnvironmentModificationService { public EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto) { Environment env = environmentService .findByNameAndAccountIdAndArchivedIsFalse(environmentName, editDto.getAccountId()) .orElseThrow(() -> new NotFoundException(String.format("No environment found with name '%s'", environmentName))); return edit(editDto, env); } EnvironmentModificationService(EnvironmentDtoConverter environmentDtoConverter, EnvironmentService environmentService,
            CredentialService credentialService, NetworkService networkService, AuthenticationDtoConverter authenticationDtoConverter,
            ParametersService parametersService, EnvironmentFlowValidatorService environmentFlowValidatorService,
            EnvironmentResourceService environmentResourceService); EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto); EnvironmentDto editByCrn(String crn, EnvironmentEditDto editDto); EnvironmentDto changeCredentialByEnvironmentName(String accountId, String environmentName, EnvironmentChangeCredentialDto dto); EnvironmentDto changeCredentialByEnvironmentCrn(String accountId, String crn, EnvironmentChangeCredentialDto dto); EnvironmentDto changeTelemetryFeaturesByEnvironmentName(String accountId, String environmentName,
            EnvironmentFeatures features); EnvironmentDto changeTelemetryFeaturesByEnvironmentCrn(String accountId, String crn,
            EnvironmentFeatures features);  }