Search in sources :

Example 6 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-web by phax.

the class CommandRunnerTest method initializeClass.

@BeforeClass
public static void initializeClass() {
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        properties = new NonBlockingProperties();
        properties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped)", e);
        properties = null;
        return;
    }
    final String knownHosts = properties.getProperty("ssh.knownHosts");
    final String privateKey = properties.getProperty("ssh.privateKey");
    final String username = properties.getProperty("scp.out.test.username");
    final String hostname = "localhost";
    final int port = Integer.parseInt(properties.getProperty("scp.out.test.port"));
    final DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(username, hostname, port);
    try {
        defaultSessionFactory.setKnownHosts(knownHosts);
        defaultSessionFactory.setIdentityFromPrivateKey(privateKey);
    } catch (final JSchException e) {
        Assume.assumeNoException(e);
    }
    sessionFactory = defaultSessionFactory;
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 7 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-web by phax.

the class SshProxyTest method initializeClass.

@BeforeClass
public static void initializeClass() {
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        properties = new NonBlockingProperties();
        properties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped)", e);
        properties = null;
        return;
    }
    final String knownHosts = properties.getProperty("ssh.knownHosts");
    final String privateKey = properties.getProperty("ssh.privateKey");
    username = properties.getProperty("scp.out.test.username");
    hostname = "localhost";
    port = Integer.parseInt(properties.getProperty("scp.out.test.port"));
    sessionFactory = new DefaultSessionFactory(username, hostname, port);
    try {
        sessionFactory.setKnownHosts(knownHosts);
        sessionFactory.setIdentityFromPrivateKey(privateKey);
    } catch (final JSchException e) {
        Assume.assumeNoException(e);
    }
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 8 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-commons by phax.

the class ConfigurationSourceProperties method reload.

@Nonnull
public ESuccess reload() {
    // Main load
    final NonBlockingProperties aProps = _load(getResource(), m_aCharset);
    // Replace in write-lock
    m_aRWLock.writeLockedGet(() -> m_aProps = aProps);
    return ESuccess.valueOf(aProps != null);
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) Nonnull(javax.annotation.Nonnull)

Example 9 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-commons by phax.

the class SettingsPersistenceProperties method readSettings.

@Nonnull
public ISettings readSettings(@Nonnull @WillClose final InputStream aIS) {
    ValueEnforcer.notNull(aIS, "InputStream");
    // Create the settings object
    final ISettings aSettings = m_aSettingsFactory.apply(getReadSettingsName());
    // Read the properties file from the input stream
    final NonBlockingProperties aProps = PropertiesHelper.loadProperties(aIS);
    if (aProps != null)
        for (final Map.Entry<String, String> aEntry : aProps.entrySet()) aSettings.putIn(aEntry.getKey(), aEntry.getValue());
    return aSettings;
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) ISettings(com.helger.settings.ISettings) Nonnull(javax.annotation.Nonnull)

Example 10 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-commons by phax.

the class XMLResourceBundleTest method testAll.

@Test
public void testAll() {
    final File aFile = new File("target/test-classes/unittest-xml-props.xml");
    try {
        // Create dummy properties file
        final NonBlockingProperties p = new NonBlockingProperties();
        p.setProperty("prop1", "Value 1");
        p.setProperty("prop2", "äöü");
        MicroWriter.writeToFile(XMLResourceBundle.getAsPropertiesXML(p), aFile);
        // Read again
        final XMLResourceBundle aRB = XMLResourceBundle.getXMLBundle("unittest-xml-props");
        assertNotNull(aRB);
        assertEquals("Value 1", aRB.getString("prop1"));
        assertEquals("äöü", aRB.getString("prop2"));
        try {
            aRB.getObject("prop3");
            fail();
        } catch (final MissingResourceException ex) {
        // expected
        }
    } finally {
        FileOperations.deleteFile(aFile);
    }
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) MissingResourceException(java.util.MissingResourceException) File(java.io.File) Test(org.junit.Test)

Aggregations

NonBlockingProperties (com.helger.commons.lang.NonBlockingProperties)10 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 BeforeClass (org.junit.BeforeClass)5 DefaultSessionFactory (com.helger.jsch.session.DefaultSessionFactory)4 JSchException (com.jcraft.jsch.JSchException)4 Nonnull (javax.annotation.Nonnull)3 ISettings (com.helger.settings.ISettings)2 File (java.io.File)1 Map (java.util.Map)1 MissingResourceException (java.util.MissingResourceException)1 Test (org.junit.Test)1