HibernateDatabaseInfoProvider implements DatabaseInfoProvider { @PostConstruct public void init() { checkDatabaseConnectivity(); boolean spatialSupport = false; if ( !SystemUtils.isTestRun(environment.getActiveProfiles()) ) { spatialSupport = isSpatialSupport(); if ( !spatialSupport ) { log.error( POSTGIS_MISSING_ERROR ); throw new IllegalStateException( POSTGIS_MISSING_ERROR ); } } String url = config.getProperty( ConfigurationKey.CONNECTION_URL ); String user = config.getProperty( ConfigurationKey.CONNECTION_USERNAME ); String password = config.getProperty( ConfigurationKey.CONNECTION_PASSWORD ); InternalDatabaseInfo internalDatabaseInfo = getInternalDatabaseInfo(); info = new DatabaseInfo(); info.setName( internalDatabaseInfo.getDatabase() ); info.setUser( StringUtils.defaultIfEmpty( internalDatabaseInfo.getUser(), user ) ); info.setPassword( password ); info.setUrl( url ); info.setSpatialSupport( spatialSupport ); info.setDatabaseVersion( internalDatabaseInfo.getVersion() ); } HibernateDatabaseInfoProvider( DhisConfigurationProvider config, JdbcOperations jdbcTemplate,
        Environment environment ); @PostConstruct void init(); @Override DatabaseInfo getDatabaseInfo(); @Override boolean isInMemory();  }
@Test @SuppressWarnings( "unchecked" ) public void init() throws SQLException { Mockito.when( jdbcTemplate.queryForObject( Mockito.eq( "select postgis_full_version();" ), Mockito.eq( String.class ) ) ).thenReturn( "2" ); Mockito.when( config.getProperty( Mockito.eq( ConfigurationKey.CONNECTION_URL ) ) ).thenReturn( "jdbc:postgresql:dhisx" ); Mockito.when( config.getProperty( Mockito.eq( ConfigurationKey.CONNECTION_USERNAME ) ) ).thenReturn( "dhisy" ); Mockito.when( config.getProperty( Mockito.eq( ConfigurationKey.CONNECTION_PASSWORD ) ) ).thenReturn( "dhisz" ); Mockito.when( resultSet.getString( Mockito.eq( 1 ) ) ).thenReturn( "PostgreSQL 10.5, compiled by Visual C++ build 1800, 64-bit" ); Mockito.when( resultSet.getString( Mockito.eq( 2 ) ) ).thenReturn( "dhis2" ); Mockito.when( resultSet.getString( Mockito.eq( 3 ) ) ).thenReturn( "dhis" ); Mockito.when( jdbcTemplate.queryForObject( Mockito.eq( "select version(),current_catalog,current_user" ), Mockito.isA( RowMapper.class ) ) ) .thenAnswer( invocation -> ( (RowMapper<?>) invocation.getArgument( 1 ) ).mapRow( resultSet, 1 ) ); provider.init(); final DatabaseInfo databaseInfo = provider.getDatabaseInfo(); Assert.assertEquals( "jdbc:postgresql:dhisx", databaseInfo.getUrl() ); Assert.assertEquals( "dhis2", databaseInfo.getName() ); Assert.assertEquals( "dhis", databaseInfo.getUser() ); Assert.assertEquals( "dhisz", databaseInfo.getPassword() ); Assert.assertEquals( "PostgreSQL 10.5", databaseInfo.getDatabaseVersion() ); Assert.assertTrue( databaseInfo.isSpatialSupport() ); }