@Test void shouldNotFailInCaseOfVaildParentChildEnvironment() { Environment environment = aValidEnvirontmentWithParent(); ValidationResult validationResult = underTest.validateParentChildRelation(environment, "parentEnvName"); assertFalse(validationResult.hasError()); }
public ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> Objects.nonNull(parentEnvironmentName) && Objects.isNull(environment.getParentEnvironment()), String.format("Active parent environment with name '%s' is not available in account '%s'.", parentEnvironmentName, environment.getAccountId())); if (Objects.nonNull(environment.getParentEnvironment())) { resultBuilder.ifError(() -> environment.getParentEnvironment().getStatus() != EnvironmentStatus.AVAILABLE, "Parent environment should be in 'AVAILABLE' status."); resultBuilder.ifError(() -> Objects.nonNull(environment.getParentEnvironment().getParentEnvironment()), "Parent environment is already a child environment."); resultBuilder.ifError(() -> !platformEnabled(enabledChildPlatforms, environment.getCloudPlatform()), String.format("'%s' platform is not supported for child environment.", environment.getCloudPlatform())); resultBuilder.ifError(() -> !platformEnabled(enabledParentPlatforms, environment.getParentEnvironment().getCloudPlatform()), String.format("'%s' platform is not supported for parent environment.", environment.getParentEnvironment().getCloudPlatform())); } return resultBuilder.build(); }
EnvironmentValidatorService { public ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> Objects.nonNull(parentEnvironmentName) && Objects.isNull(environment.getParentEnvironment()), String.format("Active parent environment with name '%s' is not available in account '%s'.", parentEnvironmentName, environment.getAccountId())); if (Objects.nonNull(environment.getParentEnvironment())) { resultBuilder.ifError(() -> environment.getParentEnvironment().getStatus() != EnvironmentStatus.AVAILABLE, "Parent environment should be in 'AVAILABLE' status."); resultBuilder.ifError(() -> Objects.nonNull(environment.getParentEnvironment().getParentEnvironment()), "Parent environment is already a child environment."); resultBuilder.ifError(() -> !platformEnabled(enabledChildPlatforms, environment.getCloudPlatform()), String.format("'%s' platform is not supported for child environment.", environment.getCloudPlatform())); resultBuilder.ifError(() -> !platformEnabled(enabledParentPlatforms, environment.getParentEnvironment().getCloudPlatform()), String.format("'%s' platform is not supported for parent environment.", environment.getParentEnvironment().getCloudPlatform())); } return resultBuilder.build(); } }
EnvironmentValidatorService { public ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> Objects.nonNull(parentEnvironmentName) && Objects.isNull(environment.getParentEnvironment()), String.format("Active parent environment with name '%s' is not available in account '%s'.", parentEnvironmentName, environment.getAccountId())); if (Objects.nonNull(environment.getParentEnvironment())) { resultBuilder.ifError(() -> environment.getParentEnvironment().getStatus() != EnvironmentStatus.AVAILABLE, "Parent environment should be in 'AVAILABLE' status."); resultBuilder.ifError(() -> Objects.nonNull(environment.getParentEnvironment().getParentEnvironment()), "Parent environment is already a child environment."); resultBuilder.ifError(() -> !platformEnabled(enabledChildPlatforms, environment.getCloudPlatform()), String.format("'%s' platform is not supported for child environment.", environment.getCloudPlatform())); resultBuilder.ifError(() -> !platformEnabled(enabledParentPlatforms, environment.getParentEnvironment().getCloudPlatform()), String.format("'%s' platform is not supported for parent environment.", environment.getParentEnvironment().getCloudPlatform())); } return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); }
EnvironmentValidatorService { public ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> Objects.nonNull(parentEnvironmentName) && Objects.isNull(environment.getParentEnvironment()), String.format("Active parent environment with name '%s' is not available in account '%s'.", parentEnvironmentName, environment.getAccountId())); if (Objects.nonNull(environment.getParentEnvironment())) { resultBuilder.ifError(() -> environment.getParentEnvironment().getStatus() != EnvironmentStatus.AVAILABLE, "Parent environment should be in 'AVAILABLE' status."); resultBuilder.ifError(() -> Objects.nonNull(environment.getParentEnvironment().getParentEnvironment()), "Parent environment is already a child environment."); resultBuilder.ifError(() -> !platformEnabled(enabledChildPlatforms, environment.getCloudPlatform()), String.format("'%s' platform is not supported for child environment.", environment.getCloudPlatform())); resultBuilder.ifError(() -> !platformEnabled(enabledParentPlatforms, environment.getParentEnvironment().getCloudPlatform()), String.format("'%s' platform is not supported for parent environment.", environment.getParentEnvironment().getCloudPlatform())); } return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation); }
EnvironmentValidatorService { public ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> Objects.nonNull(parentEnvironmentName) && Objects.isNull(environment.getParentEnvironment()), String.format("Active parent environment with name '%s' is not available in account '%s'.", parentEnvironmentName, environment.getAccountId())); if (Objects.nonNull(environment.getParentEnvironment())) { resultBuilder.ifError(() -> environment.getParentEnvironment().getStatus() != EnvironmentStatus.AVAILABLE, "Parent environment should be in 'AVAILABLE' status."); resultBuilder.ifError(() -> Objects.nonNull(environment.getParentEnvironment().getParentEnvironment()), "Parent environment is already a child environment."); resultBuilder.ifError(() -> !platformEnabled(enabledChildPlatforms, environment.getCloudPlatform()), String.format("'%s' platform is not supported for child environment.", environment.getCloudPlatform())); resultBuilder.ifError(() -> !platformEnabled(enabledParentPlatforms, environment.getParentEnvironment().getCloudPlatform()), String.format("'%s' platform is not supported for parent environment.", environment.getParentEnvironment().getCloudPlatform())); } return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation);  }