use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversion.
@Test
public void testConversion() {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setId(1L);
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setName(RESOURCE_ID);
server.setDescription("mine not yours");
server.setHost(HOST);
server.setPort(PORT);
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
initializeSecrets(server);
server.setCreationDate(System.currentTimeMillis());
server.setEnvironmentId(ENVIRONMENT_ID);
server.setClusterCrn("myclustercrn");
server.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
DBStack dbStack = new DBStack();
initDBStackStatus(dbStack);
server.setDbStack(dbStack);
when(stringToSecretResponseConverter.convert(anyString())).thenReturn(new SecretResponse());
DatabaseServerV4Response response = converter.convert(server);
verify(stringToSecretResponseConverter, times(2)).convert(anyString());
assertThat(response).isNotNull();
assertThat(response.getId()).isEqualTo(server.getId());
assertThat(response.getCrn()).isEqualTo(server.getResourceCrn().toString());
assertThat(response.getName()).isEqualTo(server.getName());
assertThat(response.getDescription()).isEqualTo(server.getDescription());
assertThat(response.getHost()).isEqualTo(server.getHost());
assertThat(response.getPort()).isEqualTo(server.getPort());
assertThat(response.getDatabaseVendor()).isEqualTo(server.getDatabaseVendor().databaseType());
assertThat(response.getDatabaseVendorDisplayName()).isEqualTo(server.getDatabaseVendor().displayName());
assertThat(response.getConnectionUserName()).isNotNull();
assertThat(response.getConnectionPassword()).isNotNull();
assertThat(response.getCreationDate()).isEqualTo(server.getCreationDate());
assertThat(response.getEnvironmentCrn()).isEqualTo(server.getEnvironmentId());
assertThat(response.getClusterCrn()).isEqualTo(server.getClusterCrn());
assertThat(response.getResourceStatus()).isEqualTo(server.getResourceStatus());
assertThat(response.getStatus()).isEqualTo(dbStack.getStatus());
assertThat(response.getStatusReason()).isEqualTo(dbStack.getStatusReason());
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned.
@ParameterizedTest(name = "{0}")
@MethodSource("testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwnedDataProvider")
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned(String testCaseName, Integer certActiveVersionInput, String certActiveCloudProviderIdentifierInput, int certActiveVersionExpected, String certActiveCloudProviderIdentifierExpected) {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
DBStack dbStack = new DBStack();
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setRegion(REGION);
SslConfig sslConfig = new SslConfig();
sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
sslConfig.setSslCertificates(CERTS);
sslConfig.setSslCertificateActiveVersion(certActiveVersionInput);
sslConfig.setSslCertificateActiveCloudProviderIdentifier(certActiveCloudProviderIdentifierInput);
dbStack.setSslConfig(sslConfig);
server.setDbStack(dbStack);
when(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_MAX_VERSION);
when(databaseServerSslCertificateConfig.getLegacyMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_MAX_VERSION);
when(databaseServerSslCertificateConfig.getLegacyCloudProviderIdentifierByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_CLOUD_PROVIDER_IDENTIFIER);
DatabaseServerV4Response response = converter.convert(server);
assertThat(response).isNotNull();
SslConfigV4Response sslConfigV4Response = response.getSslConfig();
assertThat(sslConfigV4Response).isNotNull();
assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.ENABLED);
assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.CLOUD_PROVIDER_OWNED);
assertThat(sslConfigV4Response.getSslCertificates()).isSameAs(CERTS);
assertThat(sslConfigV4Response.getSslCertificateHighestAvailableVersion()).isEqualTo(CERT_MAX_VERSION);
assertThat(sslConfigV4Response.getSslCertificateActiveVersion()).isEqualTo(certActiveVersionExpected);
assertThat(sslConfigV4Response.getSslCertificateActiveCloudProviderIdentifier()).isEqualTo(certActiveCloudProviderIdentifierExpected);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseServerV4ControllerTest method testRegister.
public void testRegister() {
when(databaseServerV4RequestToDatabaseServerConfigConverter.convert(request)).thenReturn(server);
when(service.create(server, DatabaseServerV4Controller.DEFAULT_WORKSPACE, false)).thenReturn(server);
when(databaseServerConfigToDatabaseServerV4ResponseConverter.convert(server)).thenReturn(serverResponse);
DatabaseServerV4Response response = underTest.register(request);
assertEquals(serverResponse.getId().longValue(), response.getId().longValue());
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseServerV4ControllerTest method testDeleteByCrn.
@Test
public void testDeleteByCrn() {
when(terminationService.terminateByCrn(SERVER_CRN, true)).thenReturn(server);
when(databaseServerConfigToDatabaseServerV4ResponseConverter.convert(server)).thenReturn(serverResponse);
DatabaseServerV4Response response = underTest.deleteByCrn(SERVER_CRN, true);
assertEquals(serverResponse.getId().longValue(), response.getId().longValue());
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseServerV4ControllerTest method setUp.
@Before
public void setUp() {
initMocks(this);
server = new DatabaseServerConfig();
server.setId(1L);
server.setName(SERVER_NAME);
server.setEnvironmentId(ENVIRONMENT_CRN);
server.setResourceCrn(CRN);
server2 = new DatabaseServerConfig();
server2.setId(2L);
server2.setName("myotherserver");
server2.setEnvironmentId(ENVIRONMENT_CRN);
request = new DatabaseServerV4Request();
request.setName(SERVER_NAME);
serverResponse = new DatabaseServerV4Response();
serverResponse.setId(1L);
serverResponse.setName(SERVER_NAME);
serverResponse2 = new DatabaseServerV4Response();
serverResponse2.setId(2L);
serverResponse2.setName("myotherserver");
allocateRequest = new AllocateDatabaseServerV4Request();
allocateRequest.setClusterCrn(CLUSTER_CRN);
allocateResponse = new DatabaseServerStatusV4Response();
dbStack = new DBStack();
}
Aggregations