@Test void testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName() { EnvironmentRequest request = createEnvironmentRequest(AZURE); request.setAzure(AzureEnvironmentParameters.builder() .withAzureResourceGroup( AzureResourceGroup.builder() .withName("myResourceGroup") .build()) .build()); FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class); EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class); AccountTelemetry accountTelemetry = mock(AccountTelemetry.class); Features features = mock(Features.class); NetworkDto networkDto = mock(NetworkDto.class); when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name()); when(freeIpaConverter.convert(request.getFreeIpa())).thenReturn(freeIpaCreationDto); when(accountTelemetry.getFeatures()).thenReturn(features); when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry); when(telemetryApiConverter.convert(eq(request.getTelemetry()), any())).thenReturn(environmentTelemetry); when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel()); when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto); EnvironmentCreationDto actual = underTest.initCreationDto(request); assertNull(actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern()); assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName()); }
public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) { LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT); Builder builder = EnvironmentCreationDto.builder() .withAccountId(accountId) .withCreator(ThreadBasedUserCrnProvider.getUserCrn()) .withName(request.getName()) .withDescription(request.getDescription()) .withCloudPlatform(cloudPlatform) .withCredential(request) .withCreated(System.currentTimeMillis()) .withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa())) .withLocation(locationRequestToDto(request.getLocation())) .withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures())) .withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)) .withAuthentication(authenticationRequestToDto(request.getAuthentication())) .withAdminGroupName(request.getAdminGroupName()) .withTags(request.getTags()) .withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())) .withExperimentalFeatures(ExperimentalFeatures.builder() .withIdBrokerMappingSource(request.getIdBrokerMappingSource()) .withCloudStorageValidation(request.getCloudStorageValidation()) .withTunnel(tunnelConverter.convert(request.getTunnel())) .build()) .withParameters(paramsToParametersDto(request, cloudPlatform)) .withParentEnvironmentName(request.getParentEnvironmentName()) .withProxyConfigName(request.getProxyConfigName()); NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network))); NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess))); if (request.getSecurityAccess() == null) { SecurityAccessDto securityAccess = SecurityAccessDto.builder() .withCidr("0.0.0.0/0") .build(); builder.withSecurityAccess(securityAccess); } return builder.build(); }
EnvironmentApiConverter { public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) { LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT); Builder builder = EnvironmentCreationDto.builder() .withAccountId(accountId) .withCreator(ThreadBasedUserCrnProvider.getUserCrn()) .withName(request.getName()) .withDescription(request.getDescription()) .withCloudPlatform(cloudPlatform) .withCredential(request) .withCreated(System.currentTimeMillis()) .withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa())) .withLocation(locationRequestToDto(request.getLocation())) .withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures())) .withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)) .withAuthentication(authenticationRequestToDto(request.getAuthentication())) .withAdminGroupName(request.getAdminGroupName()) .withTags(request.getTags()) .withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())) .withExperimentalFeatures(ExperimentalFeatures.builder() .withIdBrokerMappingSource(request.getIdBrokerMappingSource()) .withCloudStorageValidation(request.getCloudStorageValidation()) .withTunnel(tunnelConverter.convert(request.getTunnel())) .build()) .withParameters(paramsToParametersDto(request, cloudPlatform)) .withParentEnvironmentName(request.getParentEnvironmentName()) .withProxyConfigName(request.getProxyConfigName()); NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network))); NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess))); if (request.getSecurityAccess() == null) { SecurityAccessDto securityAccess = SecurityAccessDto.builder() .withCidr("0.0.0.0/0") .build(); builder.withSecurityAccess(securityAccess); } return builder.build(); } }
EnvironmentApiConverter { public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) { LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT); Builder builder = EnvironmentCreationDto.builder() .withAccountId(accountId) .withCreator(ThreadBasedUserCrnProvider.getUserCrn()) .withName(request.getName()) .withDescription(request.getDescription()) .withCloudPlatform(cloudPlatform) .withCredential(request) .withCreated(System.currentTimeMillis()) .withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa())) .withLocation(locationRequestToDto(request.getLocation())) .withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures())) .withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)) .withAuthentication(authenticationRequestToDto(request.getAuthentication())) .withAdminGroupName(request.getAdminGroupName()) .withTags(request.getTags()) .withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())) .withExperimentalFeatures(ExperimentalFeatures.builder() .withIdBrokerMappingSource(request.getIdBrokerMappingSource()) .withCloudStorageValidation(request.getCloudStorageValidation()) .withTunnel(tunnelConverter.convert(request.getTunnel())) .build()) .withParameters(paramsToParametersDto(request, cloudPlatform)) .withParentEnvironmentName(request.getParentEnvironmentName()) .withProxyConfigName(request.getProxyConfigName()); NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network))); NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess))); if (request.getSecurityAccess() == null) { SecurityAccessDto securityAccess = SecurityAccessDto.builder() .withCidr("0.0.0.0/0") .build(); builder.withSecurityAccess(securityAccess); } return builder.build(); } EnvironmentApiConverter(TelemetryApiConverter telemetryApiConverter,
            TunnelConverter tunnelConverter,
            AccountTelemetryService accountTelemetryService,
            CredentialService credentialService,
            FreeIpaConverter freeIpaConverter,
            NetworkRequestToDtoConverter networkRequestToDtoConverter); }
EnvironmentApiConverter { public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) { LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT); Builder builder = EnvironmentCreationDto.builder() .withAccountId(accountId) .withCreator(ThreadBasedUserCrnProvider.getUserCrn()) .withName(request.getName()) .withDescription(request.getDescription()) .withCloudPlatform(cloudPlatform) .withCredential(request) .withCreated(System.currentTimeMillis()) .withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa())) .withLocation(locationRequestToDto(request.getLocation())) .withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures())) .withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)) .withAuthentication(authenticationRequestToDto(request.getAuthentication())) .withAdminGroupName(request.getAdminGroupName()) .withTags(request.getTags()) .withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())) .withExperimentalFeatures(ExperimentalFeatures.builder() .withIdBrokerMappingSource(request.getIdBrokerMappingSource()) .withCloudStorageValidation(request.getCloudStorageValidation()) .withTunnel(tunnelConverter.convert(request.getTunnel())) .build()) .withParameters(paramsToParametersDto(request, cloudPlatform)) .withParentEnvironmentName(request.getParentEnvironmentName()) .withProxyConfigName(request.getProxyConfigName()); NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network))); NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess))); if (request.getSecurityAccess() == null) { SecurityAccessDto securityAccess = SecurityAccessDto.builder() .withCidr("0.0.0.0/0") .build(); builder.withSecurityAccess(securityAccess); } return builder.build(); } EnvironmentApiConverter(TelemetryApiConverter telemetryApiConverter,
            TunnelConverter tunnelConverter,
            AccountTelemetryService accountTelemetryService,
            CredentialService credentialService,
            FreeIpaConverter freeIpaConverter,
            NetworkRequestToDtoConverter networkRequestToDtoConverter); EnvironmentCreationDto initCreationDto(EnvironmentRequest request); EnvironmentEditDto initEditDto(EnvironmentEditRequest request); EnvironmentChangeCredentialDto convertEnvironmentChangeCredentialDto(EnvironmentChangeCredentialRequest request); EnvironmentCrnResponse crnResponse(String environmentName, String crn); EnvironmentFeatures convertToEnvironmentTelemetryFeatures(FeaturesRequest featuresRequest); }
EnvironmentApiConverter { public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) { LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT); Builder builder = EnvironmentCreationDto.builder() .withAccountId(accountId) .withCreator(ThreadBasedUserCrnProvider.getUserCrn()) .withName(request.getName()) .withDescription(request.getDescription()) .withCloudPlatform(cloudPlatform) .withCredential(request) .withCreated(System.currentTimeMillis()) .withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa())) .withLocation(locationRequestToDto(request.getLocation())) .withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures())) .withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)) .withAuthentication(authenticationRequestToDto(request.getAuthentication())) .withAdminGroupName(request.getAdminGroupName()) .withTags(request.getTags()) .withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())) .withExperimentalFeatures(ExperimentalFeatures.builder() .withIdBrokerMappingSource(request.getIdBrokerMappingSource()) .withCloudStorageValidation(request.getCloudStorageValidation()) .withTunnel(tunnelConverter.convert(request.getTunnel())) .build()) .withParameters(paramsToParametersDto(request, cloudPlatform)) .withParentEnvironmentName(request.getParentEnvironmentName()) .withProxyConfigName(request.getProxyConfigName()); NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network))); NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess))); if (request.getSecurityAccess() == null) { SecurityAccessDto securityAccess = SecurityAccessDto.builder() .withCidr("0.0.0.0/0") .build(); builder.withSecurityAccess(securityAccess); } return builder.build(); } EnvironmentApiConverter(TelemetryApiConverter telemetryApiConverter,
            TunnelConverter tunnelConverter,
            AccountTelemetryService accountTelemetryService,
            CredentialService credentialService,
            FreeIpaConverter freeIpaConverter,
            NetworkRequestToDtoConverter networkRequestToDtoConverter); EnvironmentCreationDto initCreationDto(EnvironmentRequest request); EnvironmentEditDto initEditDto(EnvironmentEditRequest request); EnvironmentChangeCredentialDto convertEnvironmentChangeCredentialDto(EnvironmentChangeCredentialRequest request); EnvironmentCrnResponse crnResponse(String environmentName, String crn); EnvironmentFeatures convertToEnvironmentTelemetryFeatures(FeaturesRequest featuresRequest);  }