use of com.sequenceiq.redbeams.service.drivers.DriverFunctions in project cloudbreak by hortonworks.
the class DatabaseServerConfigServiceTest method testCreateDatabaseOnServer.
@Test
public void testCreateDatabaseOnServer() {
when(repository.findByResourceCrn(SERVER_CRN)).thenReturn(Optional.of(server));
when(databaseConfigService.register(any(DatabaseConfig.class), eq(false))).thenAnswer((Answer<DatabaseConfig>) invocation -> {
return invocation.getArgument(0, DatabaseConfig.class);
});
when(userGeneratorService.generateUserName()).thenReturn(USERNAME);
when(passwordGeneratorService.generatePassword(any())).thenReturn(PASSWORD);
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
server.setHost("myhost");
server.setPort(5432);
server.setConnectionUserName("root");
server.setConnectionPassword("rootpassword");
String databaseName = "mydb";
String databaseType = "hive";
Optional<String> databaseDescription = Optional.of("mine not yours");
String result = underTest.createDatabaseOnServer(SERVER_CRN.toString(), databaseName, databaseType, databaseDescription);
assertEquals("created", result);
verify(driverFunctions).execWithDatabaseDriver(eq(server), any());
ArgumentCaptor<DatabaseConfig> captor = ArgumentCaptor.forClass(DatabaseConfig.class);
verify(databaseConfigService).register(captor.capture(), eq(false));
DatabaseConfig db = captor.getValue();
assertEquals(databaseName, db.getName());
assertEquals(databaseType, db.getType());
assertEquals(databaseDescription.get(), db.getDescription());
String databaseUserName = db.getConnectionUserName().getRaw();
assertEquals(USERNAME, databaseUserName);
assertNotEquals(server.getConnectionUserName(), databaseUserName);
assertEquals(PASSWORD, db.getConnectionPassword().getRaw());
}
Aggregations