Search in sources :

Example 6 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project spring-data-jdbc by spring-projects.

the class PostgresDataSourceConfiguration method createDataSource.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource()
	 */
@Override
protected DataSource createDataSource() {
    if (POSTGRESQL_CONTAINER == null) {
        PostgreSQLContainer<?> container = new PostgreSQLContainer<>();
        container.start();
        POSTGRESQL_CONTAINER = container;
    }
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl());
    dataSource.setUser(POSTGRESQL_CONTAINER.getUsername());
    dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword());
    return dataSource;
}
Also used : PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource)

Example 7 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project knox by apache.

the class JDBCUtilsTest method postgresDataSourceShouldHaveProperConnectionProperties.

@Test
public void postgresDataSourceShouldHaveProperConnectionProperties() throws Exception {
    final GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    final AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    setBasicPostgresExpectations(gatewayConfig, aliasService);
    EasyMock.replay(gatewayConfig, aliasService);
    final PGSimpleDataSource dataSource = (PGSimpleDataSource) JDBCUtils.getDataSource(gatewayConfig, aliasService);
    assertEquals("localhost", dataSource.getServerNames()[0]);
    assertEquals(5432, dataSource.getPortNumbers()[0]);
    assertEquals("sampleDatabase", dataSource.getDatabaseName());
    assertEquals("user", dataSource.getUser());
    assertEquals("password", dataSource.getPassword());
    assertFalse(dataSource.isSsl());
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 8 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project knox by apache.

the class JDBCUtilsTest method testGetPostgreSqlDatasourceFromJdbcConnectionUrl.

@Test
public void testGetPostgreSqlDatasourceFromJdbcConnectionUrl() throws Exception {
    final String connectionUrl = "jdbc:postgresql://postgresql_host:1234/testDb?user=smolnar&password=secret&ssl=true&sslmode=verify-ca&sslrootcert=/var/lib/knox/gateway/conf/postgresql/root.crt";
    final GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gatewayConfig.getDatabaseType()).andReturn(JDBCUtils.POSTGRESQL_DB_TYPE).anyTimes();
    EasyMock.expect(gatewayConfig.getDatabaseConnectionUrl()).andReturn(connectionUrl).anyTimes();
    EasyMock.replay(gatewayConfig);
    final PGSimpleDataSource dataSource = (PGSimpleDataSource) JDBCUtils.getDataSource(gatewayConfig, null);
    assertEquals("postgresql_host", dataSource.getServerNames()[0]);
    assertEquals(1234, dataSource.getPortNumbers()[0]);
    assertEquals("testDb", dataSource.getDatabaseName());
    assertEquals("smolnar", dataSource.getUser());
    assertEquals("secret", dataSource.getPassword());
    assertTrue(dataSource.isSsl());
    assertEquals(dataSource.getSslRootCert(), "/var/lib/knox/gateway/conf/postgresql/root.crt");
    EasyMock.verify(gatewayConfig);
}
Also used : PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 9 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project knox by apache.

the class JDBCUtilsTest method shouldReturnPostgresDataSource.

@Test
public void shouldReturnPostgresDataSource() throws Exception {
    final GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gatewayConfig.getDatabaseType()).andReturn(JDBCUtils.POSTGRESQL_DB_TYPE).anyTimes();
    final AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(EasyMock.anyString())).andReturn(null).anyTimes();
    EasyMock.replay(gatewayConfig, aliasService);
    assertTrue(JDBCUtils.getDataSource(gatewayConfig, aliasService) instanceof PGSimpleDataSource);
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 10 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project knox by apache.

the class JDBCUtils method createPostgresDataSource.

private static DataSource createPostgresDataSource(GatewayConfig gatewayConfig, AliasService aliasService) throws AliasServiceException {
    final PGSimpleDataSource postgresDataSource = new PGSimpleDataSource();
    if (gatewayConfig.getDatabaseConnectionUrl() != null) {
        postgresDataSource.setUrl(gatewayConfig.getDatabaseConnectionUrl());
    } else {
        postgresDataSource.setDatabaseName(gatewayConfig.getDatabaseName());
        postgresDataSource.setServerNames(new String[] { gatewayConfig.getDatabaseHost() });
        postgresDataSource.setPortNumbers(new int[] { gatewayConfig.getDatabasePort() });
        postgresDataSource.setUser(getDatabaseUser(aliasService));
        postgresDataSource.setPassword(getDatabasePassword(aliasService));
        configurePostgreSQLSsl(gatewayConfig, aliasService, postgresDataSource);
    }
    return postgresDataSource;
}
Also used : PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource)

Aggregations

PGSimpleDataSource (org.postgresql.ds.PGSimpleDataSource)83 Test (org.junit.Test)16 Connection (java.sql.Connection)7 TypeLiteral (com.google.inject.TypeLiteral)5 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)5 AccountImpl (org.eclipse.che.account.spi.AccountImpl)5 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)5 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)5 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)5 DBInitializer (org.eclipse.che.core.db.DBInitializer)5 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)5 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)5 SHA512PasswordEncryptor (org.eclipse.che.security.SHA512PasswordEncryptor)5 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 AliasService (org.apache.knox.gateway.services.security.AliasService)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4 AccountDao (org.eclipse.che.account.spi.AccountDao)3 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)3