@Test public void testConvert() { DatabaseV4Request request = new DatabaseV4Request(); request.setType(TYPE); request.setName(NAME); request.setEnvironmentCrn(ENVIRONMENT_CRN); request.setDescription(DESCRIPTION); request.setConnectionURL(CONNECTION_URL); request.setConnectionPassword(CONNECTION_PASSWORD); request.setConnectionUserName(CONNECTION_USERNAME); request.setConnectionDriver(CONNECTION_DRIVER); when(databaseVendorUtil.getVendorByJdbcUrl(CONNECTION_URL)).thenReturn(Optional.of(DatabaseVendor.POSTGRES)); DatabaseConfig databaseConfig = underTest.convert(request); assertEquals(NAME, databaseConfig.getName()); assertEquals(TYPE, databaseConfig.getType()); assertEquals(ENVIRONMENT_CRN, databaseConfig.getEnvironmentId()); assertEquals(DESCRIPTION, databaseConfig.getDescription()); assertEquals(CONNECTION_URL, databaseConfig.getConnectionURL()); assertEquals(CONNECTION_PASSWORD, databaseConfig.getConnectionPassword().getRaw()); assertEquals(CONNECTION_USERNAME, databaseConfig.getConnectionUserName().getRaw()); assertEquals(CONNECTION_DRIVER, databaseConfig.getConnectionDriver()); assertEquals(DatabaseVendor.POSTGRES, databaseConfig.getDatabaseVendor()); assertEquals(ResourceStatus.USER_MANAGED, databaseConfig.getStatus()); verify(databaseVendorUtil).getVendorByJdbcUrl(CONNECTION_URL); verify(missingResourceNameGenerator, never()).generateName(any()); }
@Override public DatabaseConfig convert(DatabaseV4Request source) { DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setName(source.getName()); databaseConfig.setDescription(source.getDescription()); databaseConfig.setConnectionURL(source.getConnectionURL()); DatabaseVendor databaseVendor = databaseVendorUtil.getVendorByJdbcUrl(source.getConnectionURL()).get(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setConnectionDriver(source.getConnectionDriver()); databaseConfig.setConnectionUserName(source.getConnectionUserName()); databaseConfig.setConnectionPassword(source.getConnectionPassword()); databaseConfig.setCreationDate(clock.getCurrentTimeMillis()); databaseConfig.setStatus(ResourceStatus.USER_MANAGED); databaseConfig.setType(source.getType()); databaseConfig.setEnvironmentId(source.getEnvironmentCrn()); return databaseConfig; }
DatabaseV4RequestToDatabaseConfigConverter extends AbstractConversionServiceAwareConverter<DatabaseV4Request, DatabaseConfig> { @Override public DatabaseConfig convert(DatabaseV4Request source) { DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setName(source.getName()); databaseConfig.setDescription(source.getDescription()); databaseConfig.setConnectionURL(source.getConnectionURL()); DatabaseVendor databaseVendor = databaseVendorUtil.getVendorByJdbcUrl(source.getConnectionURL()).get(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setConnectionDriver(source.getConnectionDriver()); databaseConfig.setConnectionUserName(source.getConnectionUserName()); databaseConfig.setConnectionPassword(source.getConnectionPassword()); databaseConfig.setCreationDate(clock.getCurrentTimeMillis()); databaseConfig.setStatus(ResourceStatus.USER_MANAGED); databaseConfig.setType(source.getType()); databaseConfig.setEnvironmentId(source.getEnvironmentCrn()); return databaseConfig; } }
DatabaseV4RequestToDatabaseConfigConverter extends AbstractConversionServiceAwareConverter<DatabaseV4Request, DatabaseConfig> { @Override public DatabaseConfig convert(DatabaseV4Request source) { DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setName(source.getName()); databaseConfig.setDescription(source.getDescription()); databaseConfig.setConnectionURL(source.getConnectionURL()); DatabaseVendor databaseVendor = databaseVendorUtil.getVendorByJdbcUrl(source.getConnectionURL()).get(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setConnectionDriver(source.getConnectionDriver()); databaseConfig.setConnectionUserName(source.getConnectionUserName()); databaseConfig.setConnectionPassword(source.getConnectionPassword()); databaseConfig.setCreationDate(clock.getCurrentTimeMillis()); databaseConfig.setStatus(ResourceStatus.USER_MANAGED); databaseConfig.setType(source.getType()); databaseConfig.setEnvironmentId(source.getEnvironmentCrn()); return databaseConfig; }  }
DatabaseV4RequestToDatabaseConfigConverter extends AbstractConversionServiceAwareConverter<DatabaseV4Request, DatabaseConfig> { @Override public DatabaseConfig convert(DatabaseV4Request source) { DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setName(source.getName()); databaseConfig.setDescription(source.getDescription()); databaseConfig.setConnectionURL(source.getConnectionURL()); DatabaseVendor databaseVendor = databaseVendorUtil.getVendorByJdbcUrl(source.getConnectionURL()).get(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setConnectionDriver(source.getConnectionDriver()); databaseConfig.setConnectionUserName(source.getConnectionUserName()); databaseConfig.setConnectionPassword(source.getConnectionPassword()); databaseConfig.setCreationDate(clock.getCurrentTimeMillis()); databaseConfig.setStatus(ResourceStatus.USER_MANAGED); databaseConfig.setType(source.getType()); databaseConfig.setEnvironmentId(source.getEnvironmentCrn()); return databaseConfig; }  @Override DatabaseConfig convert(DatabaseV4Request source); }
DatabaseV4RequestToDatabaseConfigConverter extends AbstractConversionServiceAwareConverter<DatabaseV4Request, DatabaseConfig> { @Override public DatabaseConfig convert(DatabaseV4Request source) { DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setName(source.getName()); databaseConfig.setDescription(source.getDescription()); databaseConfig.setConnectionURL(source.getConnectionURL()); DatabaseVendor databaseVendor = databaseVendorUtil.getVendorByJdbcUrl(source.getConnectionURL()).get(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setConnectionDriver(source.getConnectionDriver()); databaseConfig.setConnectionUserName(source.getConnectionUserName()); databaseConfig.setConnectionPassword(source.getConnectionPassword()); databaseConfig.setCreationDate(clock.getCurrentTimeMillis()); databaseConfig.setStatus(ResourceStatus.USER_MANAGED); databaseConfig.setType(source.getType()); databaseConfig.setEnvironmentId(source.getEnvironmentCrn()); return databaseConfig; }  @Override DatabaseConfig convert(DatabaseV4Request source);  }