package no.valg.valgnatt.database;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashSet;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DatabaseTestHibernateSpringConfiguration.class)
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:enhetstest.properties")
public class ConfigurationTest {

    @Resource
    private Environment environment;

    @Test
    public void afterPropertiesSet() {
        Configuration configuration = new Configuration();
        configuration.setEnvironment(environment);
        configuration.afterPropertiesSet();

        assertEquals("http://host:8080/valg_mottak/", configuration.getMottakFromURL());
        assertEquals("full_2013", configuration.getInitialdata());
        assertEquals("schema", configuration.getFlywaySchemas());
        assertEquals(new HashSet<>(Arrays.asList("A", "SV", "SP", "KRF", "MDG", "V", "H", "FRP")), configuration.getBetaPartier());
        assertArrayEquals(new String[]{}, configuration.getFrontendOffentligURLer());
        assertArrayEquals(new String[]{"http://user:password@localhost:8080/valg_frontend"}, configuration.getFrontendMediaURLer());
        assertFalse(configuration.isSuspendAtStartup());
        assertFalse(configuration.erNullstillingTillatt());
        assertFalse(configuration.ignorerUkjentePartier());
    }
}
