Search in sources :

Example 1 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesFileReaderTest method loadInputStreamTest.

@SuppressWarnings("unchecked")
@Test(expectedExceptions = { PropertiesFileException.class })
public void loadInputStreamTest() throws PropertiesFileException, IOException {
    InputStream stream = mock(InputStream.class);
    when(stream.read()).thenThrow(IOException.class);
    new BaseFileReader().loadInputStream(stream);
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) InputStream(java.io.InputStream) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesFileReaderTest method testWithValidData2.

@Test
public void testWithValidData2() throws PropertiesFileException {
    File file = new File(getClass().getClassLoader().getResource("classes.properties").getFile());
    assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
    assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) File(java.io.File) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesFileWriterTest method test.

@Test
public void test() throws PropertiesFileException {
    Properties properties = new Properties();
    properties.setProperty("hello", "word");
    new BaseFileWriter().write(properties, "hello.output_test");
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 4 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException 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 5 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesInputStreamReader method readInputStream.

@Override
public Properties readInputStream(InputStream inputStream) {
    Properties properties = new Properties();
    try {
        byte[] contentBytes = InputStreamUtil.toByteArray(inputStream);
        ByteArrayInputStream stream = new ByteArrayInputStream(contentBytes);
        try {
            properties.load(stream);
        } finally {
            stream.close();
            inputStream.close();
        }
    } catch (IOException e) {
        throw new PropertiesFileException("Can not read properties file", e);
    }
    return properties;
}
Also used : PropertiesFileException(com.tvd12.properties.file.exception.PropertiesFileException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

Test (org.testng.annotations.Test)8 Properties (java.util.Properties)6 BaseFileReader (com.tvd12.properties.file.reader.BaseFileReader)4 BaseFileWriter (com.tvd12.properties.file.writer.BaseFileWriter)4 BaseTest (com.tvd12.test.base.BaseTest)4 PropertiesFileException (com.tvd12.properties.file.exception.PropertiesFileException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1