@Test public void testConversionWhenRequestAndEnvironmentCloudplatformsDiffer() { when(crnUserDetailsService.loadUserByUsername(OWNER_CRN)).thenReturn(getCrnUser()); allocateRequest.setCloudPlatform(AWS_CLOUD_PLATFORM); allocateRequest.setEnvironmentCrn(ENVIRONMENT_CRN); DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.Builder.builder() .withCloudPlatform(UNKNOWN_CLOUD_PLATFORM) .build(); when(environmentService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment); thrown.expect(BadRequestException.class); thrown.expectMessage("Cloud platform of the request AWS and the environment " + UNKNOWN_CLOUD_PLATFORM + " do not match."); underTest.convert(allocateRequest, OWNER_CRN); }
public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) { Crn ownerCrn = Crn.safeFromString(ownerCrnString); CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString); DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn()); DBStack dbStack = new DBStack(); dbStack.setOwnerCrn(ownerCrn); dbStack.setUserName(user.getEmail()); CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform()); dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName())); dbStack.setEnvironmentId(source.getEnvironmentCrn()); setRegion(dbStack, environment); if (source.getDatabaseServer() != null) { dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, source.getName(), ownerCrn, environment.getSecurityAccess())); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); dbStack.setParameters(parameter); } dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack)); Instant now = clock.getCurrentInstant(); dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli())); dbStack.setResourceCrn(crnService.createCrn(dbStack)); dbStack.setTags(getTags(dbStack, source.getClusterCrn(), environment)); return dbStack; }
AllocateDatabaseServerV4RequestToDBStackConverter { public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) { Crn ownerCrn = Crn.safeFromString(ownerCrnString); CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString); DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn()); DBStack dbStack = new DBStack(); dbStack.setOwnerCrn(ownerCrn); dbStack.setUserName(user.getEmail()); CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform()); dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName())); dbStack.setEnvironmentId(source.getEnvironmentCrn()); setRegion(dbStack, environment); if (source.getDatabaseServer() != null) { dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, source.getName(), ownerCrn, environment.getSecurityAccess())); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); dbStack.setParameters(parameter); } dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack)); Instant now = clock.getCurrentInstant(); dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli())); dbStack.setResourceCrn(crnService.createCrn(dbStack)); dbStack.setTags(getTags(dbStack, source.getClusterCrn(), environment)); return dbStack; } }
AllocateDatabaseServerV4RequestToDBStackConverter { public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) { Crn ownerCrn = Crn.safeFromString(ownerCrnString); CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString); DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn()); DBStack dbStack = new DBStack(); dbStack.setOwnerCrn(ownerCrn); dbStack.setUserName(user.getEmail()); CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform()); dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName())); dbStack.setEnvironmentId(source.getEnvironmentCrn()); setRegion(dbStack, environment); if (source.getDatabaseServer() != null) { dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, source.getName(), ownerCrn, environment.getSecurityAccess())); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); dbStack.setParameters(parameter); } dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack)); Instant now = clock.getCurrentInstant(); dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli())); dbStack.setResourceCrn(crnService.createCrn(dbStack)); dbStack.setTags(getTags(dbStack, source.getClusterCrn(), environment)); return dbStack; }  }
AllocateDatabaseServerV4RequestToDBStackConverter { public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) { Crn ownerCrn = Crn.safeFromString(ownerCrnString); CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString); DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn()); DBStack dbStack = new DBStack(); dbStack.setOwnerCrn(ownerCrn); dbStack.setUserName(user.getEmail()); CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform()); dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName())); dbStack.setEnvironmentId(source.getEnvironmentCrn()); setRegion(dbStack, environment); if (source.getDatabaseServer() != null) { dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, source.getName(), ownerCrn, environment.getSecurityAccess())); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); dbStack.setParameters(parameter); } dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack)); Instant now = clock.getCurrentInstant(); dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli())); dbStack.setResourceCrn(crnService.createCrn(dbStack)); dbStack.setTags(getTags(dbStack, source.getClusterCrn(), environment)); return dbStack; }  @PostConstruct void initSupportedPlatforms(); DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString); }
AllocateDatabaseServerV4RequestToDBStackConverter { public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) { Crn ownerCrn = Crn.safeFromString(ownerCrnString); CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString); DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn()); DBStack dbStack = new DBStack(); dbStack.setOwnerCrn(ownerCrn); dbStack.setUserName(user.getEmail()); CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform()); dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName())); dbStack.setEnvironmentId(source.getEnvironmentCrn()); setRegion(dbStack, environment); if (source.getDatabaseServer() != null) { dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, source.getName(), ownerCrn, environment.getSecurityAccess())); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); dbStack.setParameters(parameter); } dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack)); Instant now = clock.getCurrentInstant(); dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli())); dbStack.setResourceCrn(crnService.createCrn(dbStack)); dbStack.setTags(getTags(dbStack, source.getClusterCrn(), environment)); return dbStack; }  @PostConstruct void initSupportedPlatforms(); DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString);  }