Search in sources :

Example 1 with MultiFileReader

use of com.tvd12.properties.file.reader.MultiFileReader in project properties-file by tvd12.

the class MultiFileReaderTest method readNoProfiles.

@Test
public void readNoProfiles() {
    FileReader reader = new MultiFileReader();
    Properties properties = reader.read("application1.properties");
    Asserts.assertNull(properties.get("include.profiles"));
}
Also used : MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) FileReader(com.tvd12.properties.file.reader.FileReader) MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 2 with MultiFileReader

use of com.tvd12.properties.file.reader.MultiFileReader in project properties-file by tvd12.

the class MultiFileReader method read.

private Properties read(ClassLoader classLoader, String filePath, Set<String> passedFilePaths) {
    List<String> filePaths = new ArrayList<>();
    filePaths.add(filePath);
    for (String profile : includeProfiles) {
        filePaths.add(getFileClasspathByProfile(filePath, profile));
    }
    filePaths.removeAll(passedFilePaths);
    Properties properties = new Properties();
    for (String fp : filePaths) {
        if (passedFilePaths.contains(fp)) {
            continue;
        }
        Properties prop;
        try {
            prop = super.read(classLoader, fp);
        } catch (PropertiesFileException e) {
            continue;
        }
        passedFilePaths.add(fp);
        properties.putAll(prop);
        String profilesString = prop.getProperty(Constants.PROFILES_KEY);
        List<String> profiles = getIncludeProfiles(profilesString);
        if (profiles.size() > 0) {
            properties.putAll(new MultiFileReader(profiles).read(classLoader, filePath, passedFilePaths));
        }
    }
    return properties;
}
Also used : PropertiesFileException(com.tvd12.properties.file.exception.PropertiesFileException) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 3 with MultiFileReader

use of com.tvd12.properties.file.reader.MultiFileReader in project properties-file by tvd12.

the class MultiFileReaderTest method readEmptyProfiles.

@Test
public void readEmptyProfiles() {
    FileReader reader = new MultiFileReader("alpha,");
    Properties properties = reader.read("application1.properties");
    Asserts.assertNull(properties.get("include.profiles"));
}
Also used : MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) FileReader(com.tvd12.properties.file.reader.FileReader) MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 4 with MultiFileReader

use of com.tvd12.properties.file.reader.MultiFileReader in project properties-file by tvd12.

the class MultiFileReaderTest method readClassPathFiles.

@Test
public void readClassPathFiles() {
    FileReader reader = new MultiFileReader(Arrays.asList("alpha", ""));
    Properties properties = reader.read("application.yaml");
    System.out.println(properties);
    Asserts.assertNull(properties.get("include.profiles"));
    assert properties.get("cors.allow_origin").equals("*");
    assert properties.get("cors.enable").equals("true");
    assert properties.get("server.port").equals("3005");
    assert properties.get("server.host").equals("1.1.1.1");
    assert properties.get("server.admin.username").equals("admin");
    assert properties.get("server.admin.password").equals("123456");
    assert properties.get("hello").equals("world");
    assert properties.get("foo").equals("bar");
}
Also used : MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) FileReader(com.tvd12.properties.file.reader.FileReader) MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 5 with MultiFileReader

use of com.tvd12.properties.file.reader.MultiFileReader in project properties-file by tvd12.

the class MultiFileReaderTest method readSystemFiles.

@Test
public void readSystemFiles() {
    FileReader reader = new MultiFileReader(Arrays.asList("alpha", ""));
    Properties properties = reader.read(new File("test/config/application.yaml"));
    System.out.println(properties);
    Asserts.assertNull(properties.get("include.profiles"));
    assert properties.get("cors.allow_origin").equals("*");
    assert properties.get("cors.enable").equals("true");
    Asserts.assertEquals("3006", properties.get("server.port"));
    assert properties.get("server.host").equals("2.2.2.2");
    assert properties.get("server.admin.username").equals("admin");
    assert properties.get("server.admin.password").equals("123456");
    assert properties.get("hello").equals("world");
    assert properties.get("foo").equals("bar");
}
Also used : MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) FileReader(com.tvd12.properties.file.reader.FileReader) MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader) Properties(java.util.Properties) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Properties (java.util.Properties)10 MultiFileReader (com.tvd12.properties.file.reader.MultiFileReader)9 FileReader (com.tvd12.properties.file.reader.FileReader)8 Test (org.testng.annotations.Test)8 File (java.io.File)2 PropertiesFileException (com.tvd12.properties.file.exception.PropertiesFileException)1 PropertiesMapper (com.tvd12.properties.file.mapping.PropertiesMapper)1 BaseFileReader (com.tvd12.properties.file.reader.BaseFileReader)1 ArrayList (java.util.ArrayList)1