Search in sources :

Example 1 with SftpFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder in project jackrabbit by apache.

the class TestVFSDataStore method doSetFileSystemOptionsPropertiesInString.

/**
     * Test {@link VFSDataStore#setFileSystemOptionsPropertiesInString(String)} and validate the internal properties.
     */
protected void doSetFileSystemOptionsPropertiesInString() throws Exception {
    dataStore = new VFSDataStore();
    Properties props = getConfigProps();
    baseFolderUri = props.getProperty(VFSDataStore.BASE_FOLDER_URI);
    dataStore.setBaseFolderUri(baseFolderUri);
    LOG.info("baseFolderUri [{}] set.", baseFolderUri);
    dataStore.setFileSystemOptionsProperties(props);
    dataStore.setSecret("123456");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(SFTP_FILE_SYSTEM_OPTIONS_PARAM_XML)));
    Element paramElem = document.getDocumentElement();
    String propsInString = paramElem.getAttribute("value");
    dataStore.setFileSystemOptionsPropertiesInString(propsInString);
    final Properties internalProps = dataStore.getFileSystemOptionsProperties();
    Assert.assertEquals("/home/tester/.ssh/id_rsa", internalProps.getProperty("fso.sftp.identities"));
    Assert.assertEquals("30000", internalProps.getProperty("fso.sftp.timeout"));
    dataStore.init(dataStoreDir);
    final FileSystemOptions fso = dataStore.getFileSystemOptions();
    final SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance();
    File[] identities = configBuilder.getIdentities(fso);
    Assert.assertNotNull(identities);
    Assert.assertEquals(1, identities.length);
    Assert.assertEquals("/home/tester/.ssh/id_rsa", FilenameUtils.separatorsToUnix(identities[0].getPath()));
    Assert.assertEquals(Integer.valueOf(30000), configBuilder.getTimeout(fso));
    dataStore.close();
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) SftpFileSystemConfigBuilder(org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder) Properties(java.util.Properties) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) File(java.io.File) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

File (java.io.File)1 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 SftpFileSystemConfigBuilder (org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 InputSource (org.xml.sax.InputSource)1