Search in sources :

Example 51 with DatabaseServerV4Response

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());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with DatabaseServerV4Response

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);
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 53 with DatabaseServerV4Response

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());
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)

Example 54 with DatabaseServerV4Response

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());
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Test(org.junit.Test)

Example 55 with DatabaseServerV4Response

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();
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.DatabaseServerV4Request) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) Before(org.junit.Before)

Aggregations

DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)54 Test (org.junit.jupiter.api.Test)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)16 SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)9 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Test (org.junit.Test)6 StackDatabaseServerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.StackDatabaseServerResponse)5 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)5 DatabaseServerSslConfig (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseServerSslConfig)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 DatabaseServerStatusV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response)4 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)4 Date (java.util.Date)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)3 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)3 NotFoundException (javax.ws.rs.NotFoundException)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3