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());
}
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;
}
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);
}
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);
}
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());
}
Aggregations