package no.valg.valgnatt.database;

import java.util.Properties;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

@Profile("test")
@Configuration
public class DatabaseTestHibernateSpringConfiguration {

    @Resource
    private Environment env;

    @Bean
    public Properties hibernateProperties(){
        Properties props = new Properties();
        DatabaseProdHibernateSpringConfiguration.leggTilFellesPropertiesForTestOgProd(props);
        return props;
    }

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource(env.getProperty("flyway.url"), env.getProperty("flyway.user"), env.getProperty("flyway.password"));
        dataSource.setDriverClassName(env.getProperty("flyway.driver"));
        return dataSource;
    }

}
