Search in sources :

Example 1 with DatabaseConfig

use of com.sequenceiq.redbeams.domain.DatabaseConfig in project cloudbreak by hortonworks.

the class CrnServiceTest method testCreateCrnDatabaseConfig.

@Test
public void testCreateCrnDatabaseConfig() {
    DatabaseConfig resource = new DatabaseConfig();
    Crn crn = ThreadBasedUserCrnProvider.doAs(CRN.toString(), () -> crnService.createCrn(resource));
    assertEquals(Crn.Service.REDBEAMS, crn.getService());
    assertEquals(CRN.getAccountId(), crn.getAccountId());
    assertEquals(Crn.ResourceType.DATABASE, crn.getResourceType());
    assertEquals("uuid", crn.getResource());
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Example 2 with DatabaseConfig

use of com.sequenceiq.redbeams.domain.DatabaseConfig in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method getDatabaseConfig.

private DatabaseConfig getDatabaseConfig(ResourceStatus resourceStatus, String name) {
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setStatus(resourceStatus);
    databaseConfig.setName(DATABASE_NAME);
    databaseConfig.setConnectionUserName(DATABASE_USER_NAME);
    databaseConfig.setResourceCrn(DB_CRN);
    return databaseConfig;
}
Also used : DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig)

Example 3 with DatabaseConfig

use of com.sequenceiq.redbeams.domain.DatabaseConfig in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method testDeleteByCrnRegisteredDatabase.

@Test
public void testDeleteByCrnRegisteredDatabase() {
    DatabaseConfig databaseConfig = getDatabaseConfig(ResourceStatus.USER_MANAGED, DATABASE_NAME);
    when(repository.findByResourceCrn(DB_CRN)).thenReturn(Optional.of(databaseConfig));
    underTest.deleteByCrn(DB_CRN_STRING);
    assertTrue(databaseConfig.isArchived());
    verify(repository).save(databaseConfig);
}
Also used : DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Example 4 with DatabaseConfig

use of com.sequenceiq.redbeams.domain.DatabaseConfig in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method testRegisterHasNoAccess.

@Test
public void testRegisterHasNoAccess() {
    thrown.expect(AccessDeniedException.class);
    DatabaseConfig configToRegister = new DatabaseConfig();
    configToRegister.setConnectionDriver("org.postgresql.MyCustomDriver");
    when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME_MILLIS);
    when(crnService.createCrn(configToRegister)).thenReturn(TestData.getTestCrn("database", "name"));
    when(repository.save(configToRegister)).thenThrow(new AccessDeniedException("User has no right to access resource"));
    underTest.register(configToRegister, false);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Example 5 with DatabaseConfig

use of com.sequenceiq.redbeams.domain.DatabaseConfig in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method testRegister.

@Test
public void testRegister() {
    DatabaseConfig configToRegister = new DatabaseConfig();
    configToRegister.setConnectionDriver("org.postgresql.MyCustomDriver");
    configToRegister.setResourceCrn(null);
    configToRegister.setCreationDate(null);
    when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME_MILLIS);
    Crn dbCrn = TestData.getTestCrn("database", "name");
    when(crnService.createCrn(configToRegister)).thenReturn(dbCrn);
    when(repository.save(configToRegister)).thenReturn(configToRegister);
    DatabaseConfig createdConfig = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.register(configToRegister, false));
    assertEquals(configToRegister, createdConfig);
    verify(repository).save(configToRegister);
    assertEquals(CURRENT_TIME_MILLIS, createdConfig.getCreationDate().longValue());
    assertEquals(dbCrn, createdConfig.getResourceCrn());
    assertEquals(dbCrn.getAccountId(), createdConfig.getAccountId());
    assertEquals("org.postgresql.MyCustomDriver", createdConfig.getConnectionDriver());
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Aggregations

DatabaseConfig (com.sequenceiq.redbeams.domain.DatabaseConfig)38 Test (org.junit.Test)26 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)12 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)6 NotFoundException (com.sequenceiq.redbeams.exception.NotFoundException)6 SQLException (java.sql.SQLException)6 HashSet (java.util.HashSet)6 Before (org.junit.Before)6 OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)5 DatabaseVendor (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor)5 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)5 DatabaseCommon (com.sequenceiq.cloudbreak.common.database.DatabaseCommon)5 Clock (com.sequenceiq.cloudbreak.common.service.Clock)5 ResourceStatus (com.sequenceiq.redbeams.api.endpoint.v4.ResourceStatus)5 CrnService (com.sequenceiq.redbeams.service.crn.CrnService)5 DriverFunctions (com.sequenceiq.redbeams.service.drivers.DriverFunctions)5 Optional (java.util.Optional)5 Supplier (java.util.function.Supplier)5