@Test public void testConversion() { DatabaseServerConfig server = new DatabaseServerConfig(); server.setId(1L); server.setResourceCrn(TestData.getTestCrn("databaseServer", "myserver")); server.setName("myserver"); server.setDescription("mine not yours"); server.setHost("myserver.db.example.com"); server.setPort(5432); server.setDatabaseVendor(DatabaseVendor.POSTGRES); server.setConnectionUserName("root"); server.setConnectionPassword("cloudera"); server.setCreationDate(System.currentTimeMillis()); server.setEnvironmentId("myenvironment"); server.setResourceStatus(ResourceStatus.SERVICE_MANAGED); DBStack dbStack = new DBStack(); DBStackStatus dbStackStatus = new DBStackStatus(); dbStackStatus.setStatus(Status.CREATE_IN_PROGRESS); dbStackStatus.setStatusReason("Lorem ipsum"); dbStack.setDBStackStatus(dbStackStatus); server.setDbStack(dbStack); when(conversionService.convert(any(), any())).thenReturn(new SecretResponse()); DatabaseServerV4Response response = converter.convert(server); verify(conversionService, times(2)).convert(any(), any()); assertEquals(server.getId(), response.getId()); assertEquals(server.getResourceCrn().toString(), response.getCrn()); assertEquals(server.getName(), response.getName()); assertEquals(server.getDescription(), response.getDescription()); assertEquals(server.getHost(), response.getHost()); assertEquals(server.getPort(), response.getPort()); assertEquals(server.getDatabaseVendor().databaseType(), response.getDatabaseVendor()); assertEquals(server.getDatabaseVendor().displayName(), response.getDatabaseVendorDisplayName()); assertNotNull(response.getConnectionUserName()); assertNotNull(response.getConnectionPassword()); assertEquals(server.getCreationDate(), response.getCreationDate()); assertEquals(server.getEnvironmentId(), response.getEnvironmentCrn()); assertEquals(server.getResourceStatus(), response.getResourceStatus()); assertEquals(server.getDbStack().get().getStatus(), response.getStatus()); assertEquals(server.getDbStack().get().getStatusReason(), response.getStatusReason()); }
@Override public DatabaseServerV4Response convert(DatabaseServerConfig source) { DatabaseServerV4Response response = new DatabaseServerV4Response(); response.setId(source.getId()); response.setCrn(source.getResourceCrn().toString()); response.setName(source.getName()); response.setDescription(source.getDescription()); response.setHost(source.getHost()); response.setPort(source.getPort()); response.setDatabaseVendor(source.getDatabaseVendor().databaseType()); response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName()); response.setConnectionDriver(source.getConnectionDriver()); response.setConnectionUserName(getConversionService().convert(source.getConnectionUserNameSecret(), SecretResponse.class)); response.setConnectionPassword(getConversionService().convert(source.getConnectionPasswordSecret(), SecretResponse.class)); response.setCreationDate(source.getCreationDate()); response.setEnvironmentCrn(source.getEnvironmentId()); response.setResourceStatus(source.getResourceStatus()); if (source.getDbStack().isPresent()) { DBStack dbStack = source.getDbStack().get(); response.setStatus(dbStack.getStatus()); response.setStatusReason(dbStack.getStatusReason()); } else if (source.getHost() != null && source.getPort() != null) { response.setStatus(Status.AVAILABLE); } else { response.setStatus(Status.UNKNOWN); } return response; }
DatabaseServerConfigToDatabaseServerV4ResponseConverter extends AbstractConversionServiceAwareConverter<DatabaseServerConfig, DatabaseServerV4Response> { @Override public DatabaseServerV4Response convert(DatabaseServerConfig source) { DatabaseServerV4Response response = new DatabaseServerV4Response(); response.setId(source.getId()); response.setCrn(source.getResourceCrn().toString()); response.setName(source.getName()); response.setDescription(source.getDescription()); response.setHost(source.getHost()); response.setPort(source.getPort()); response.setDatabaseVendor(source.getDatabaseVendor().databaseType()); response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName()); response.setConnectionDriver(source.getConnectionDriver()); response.setConnectionUserName(getConversionService().convert(source.getConnectionUserNameSecret(), SecretResponse.class)); response.setConnectionPassword(getConversionService().convert(source.getConnectionPasswordSecret(), SecretResponse.class)); response.setCreationDate(source.getCreationDate()); response.setEnvironmentCrn(source.getEnvironmentId()); response.setResourceStatus(source.getResourceStatus()); if (source.getDbStack().isPresent()) { DBStack dbStack = source.getDbStack().get(); response.setStatus(dbStack.getStatus()); response.setStatusReason(dbStack.getStatusReason()); } else if (source.getHost() != null && source.getPort() != null) { response.setStatus(Status.AVAILABLE); } else { response.setStatus(Status.UNKNOWN); } return response; } }
DatabaseServerConfigToDatabaseServerV4ResponseConverter extends AbstractConversionServiceAwareConverter<DatabaseServerConfig, DatabaseServerV4Response> { @Override public DatabaseServerV4Response convert(DatabaseServerConfig source) { DatabaseServerV4Response response = new DatabaseServerV4Response(); response.setId(source.getId()); response.setCrn(source.getResourceCrn().toString()); response.setName(source.getName()); response.setDescription(source.getDescription()); response.setHost(source.getHost()); response.setPort(source.getPort()); response.setDatabaseVendor(source.getDatabaseVendor().databaseType()); response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName()); response.setConnectionDriver(source.getConnectionDriver()); response.setConnectionUserName(getConversionService().convert(source.getConnectionUserNameSecret(), SecretResponse.class)); response.setConnectionPassword(getConversionService().convert(source.getConnectionPasswordSecret(), SecretResponse.class)); response.setCreationDate(source.getCreationDate()); response.setEnvironmentCrn(source.getEnvironmentId()); response.setResourceStatus(source.getResourceStatus()); if (source.getDbStack().isPresent()) { DBStack dbStack = source.getDbStack().get(); response.setStatus(dbStack.getStatus()); response.setStatusReason(dbStack.getStatusReason()); } else if (source.getHost() != null && source.getPort() != null) { response.setStatus(Status.AVAILABLE); } else { response.setStatus(Status.UNKNOWN); } return response; }  }
DatabaseServerConfigToDatabaseServerV4ResponseConverter extends AbstractConversionServiceAwareConverter<DatabaseServerConfig, DatabaseServerV4Response> { @Override public DatabaseServerV4Response convert(DatabaseServerConfig source) { DatabaseServerV4Response response = new DatabaseServerV4Response(); response.setId(source.getId()); response.setCrn(source.getResourceCrn().toString()); response.setName(source.getName()); response.setDescription(source.getDescription()); response.setHost(source.getHost()); response.setPort(source.getPort()); response.setDatabaseVendor(source.getDatabaseVendor().databaseType()); response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName()); response.setConnectionDriver(source.getConnectionDriver()); response.setConnectionUserName(getConversionService().convert(source.getConnectionUserNameSecret(), SecretResponse.class)); response.setConnectionPassword(getConversionService().convert(source.getConnectionPasswordSecret(), SecretResponse.class)); response.setCreationDate(source.getCreationDate()); response.setEnvironmentCrn(source.getEnvironmentId()); response.setResourceStatus(source.getResourceStatus()); if (source.getDbStack().isPresent()) { DBStack dbStack = source.getDbStack().get(); response.setStatus(dbStack.getStatus()); response.setStatusReason(dbStack.getStatusReason()); } else if (source.getHost() != null && source.getPort() != null) { response.setStatus(Status.AVAILABLE); } else { response.setStatus(Status.UNKNOWN); } return response; }  @Override DatabaseServerV4Response convert(DatabaseServerConfig source); }
DatabaseServerConfigToDatabaseServerV4ResponseConverter extends AbstractConversionServiceAwareConverter<DatabaseServerConfig, DatabaseServerV4Response> { @Override public DatabaseServerV4Response convert(DatabaseServerConfig source) { DatabaseServerV4Response response = new DatabaseServerV4Response(); response.setId(source.getId()); response.setCrn(source.getResourceCrn().toString()); response.setName(source.getName()); response.setDescription(source.getDescription()); response.setHost(source.getHost()); response.setPort(source.getPort()); response.setDatabaseVendor(source.getDatabaseVendor().databaseType()); response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName()); response.setConnectionDriver(source.getConnectionDriver()); response.setConnectionUserName(getConversionService().convert(source.getConnectionUserNameSecret(), SecretResponse.class)); response.setConnectionPassword(getConversionService().convert(source.getConnectionPasswordSecret(), SecretResponse.class)); response.setCreationDate(source.getCreationDate()); response.setEnvironmentCrn(source.getEnvironmentId()); response.setResourceStatus(source.getResourceStatus()); if (source.getDbStack().isPresent()) { DBStack dbStack = source.getDbStack().get(); response.setStatus(dbStack.getStatus()); response.setStatusReason(dbStack.getStatusReason()); } else if (source.getHost() != null && source.getPort() != null) { response.setStatus(Status.AVAILABLE); } else { response.setStatus(Status.UNKNOWN); } return response; }  @Override DatabaseServerV4Response convert(DatabaseServerConfig source);  }