package org.dainst.chronontology;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

/**
 * @author Daniel M. de Oliveira
 */
public class AppConfigTest {

    private AppConfig appConfig;

    @BeforeMethod
    public void before() {
        appConfig= new AppConfig();
    }

    @Test
    public void basic() {
        appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.1.properties");
        assertEquals(appConfig.getServerPort(),"4567");
        assertEquals(appConfig.getEsIndexName(),"jeremy");
        assertEquals(appConfig.getCredentials()[0],"admin:s3cr3t");
    }

    @Test
    public void missingRequiredProperty() {
        assertFalse(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.2.properties"));
    }

    @Test
    public void useEmbeddedES() {
        appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.3.properties");
        assertEquals(appConfig.isUseEmbeddedES(),true);
    }

    @Test
    public void dontUseEmbeddedESBySettingParamFalse() {
        appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.4.properties");
        assertEquals(appConfig.isUseEmbeddedES(),false);
    }

    /**
     * Omitting param is supported for backward compatibility.
     */
    @Test
    public void dontUseEmbeddedESByOmittingParam() {
        assertTrue(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.5.properties"));
        assertEquals(appConfig.isUseEmbeddedES(),false);
    }

    @Test
    public void overrideESUrlWhenUsingEmbeddedES() {
        assertTrue(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.6.properties"));
        assertEquals(appConfig.isUseEmbeddedES(),true);
        assertEquals(appConfig.getEsUrl(),Constants.EMBEDDED_ES_URL);
    }

    @Test
    public void allowOmitEsUrlWhenUsingEmbeddedES() {
        assertTrue(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.7.properties"));
        assertEquals(appConfig.isUseEmbeddedES(),true);
        assertEquals(appConfig.getEsUrl(),Constants.EMBEDDED_ES_URL);
    }

    @Test
    public void dontAllowOmitEsUrlWhenNotUsingEmbeddedES() {
        assertFalse(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.8.properties"));
    }

    @Test
    public void omitDatastorePath() {
        assertTrue(appConfig.loadConfiguration(TestConstants.TEST_FOLDER+"config.9.properties"));
        assertEquals(appConfig.getDataStorePath(),Constants.DATASTORE_PATH);
    }
}

@@ -430,32 +430,158 @@
 onfig();%0A    %7D%0A%0A
+    private String propsFile(String number) %7B%0A        return TestConstants.TEST_FOLDER+%22config.%22+number+%22.properties%22;%0A    %7D%0A%0A
     @Test%0A    pu
@@ -640,55 +640,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.1.properties%22
+propsFile(%221%22)
 );%0A 
@@ -949,55 +949,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.2.properties%22
+propsFile(%222%22)
 ));%0A
@@ -1054,55 +1054,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.3.properties%22
+propsFile(%223%22)
 );%0A 
@@ -1237,55 +1237,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.4.properties%22
+propsFile(%224%22)
 );%0A 
@@ -1507,55 +1507,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.5.properties%22
+propsFile(%225%22)
 ));%0A
@@ -1699,55 +1699,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.6.properties%22
+propsFile(%226%22)
 ));%0A
@@ -1961,55 +1961,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.7.properties%22
+propsFile(%227%22)
 ));%0A
@@ -2231,55 +2231,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.8.properties%22
+propsFile(%228%22)
 ));%0A
@@ -2351,55 +2351,22 @@
 ion(
-TestConstants.TEST_FOLDER+%22config.9.properties%22
+propsFile(%229%22)
 ));%0A

Create method to express test file naming pattern.