You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/10/06 22:19:57 UTC
svn commit: r1179819 -
/oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
Author: bfoster
Date: Thu Oct 6 20:19:57 2011
New Revision: 1179819
URL: http://svn.apache.org/viewvc?rev=1179819&view=rev
Log:
- let's try this yet again!
Modified:
oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
Modified: oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java?rev=1179819&r1=1179818&r2=1179819&view=diff
==============================================================================
--- oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java (original)
+++ oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java Thu Oct 6 20:19:57 2011
@@ -53,53 +53,12 @@ import junit.framework.TestCase;
*/
public class TestJschSftpProtocol extends TestCase {
- private TestServerConfiguration serverConfig;
- private PlatformConfiguration platformConfig;
+ TestXmlServerConfigurationContext context;
@Override
public void setUp() {
- XmlServerConfigurationContext context = new XmlServerConfigurationContext() {
-
- @Override
- public void initialize() throws ConfigurationException {
- try {
- serverConfig = new TestServerConfiguration(ConfigurationLoader.loadFile("src/testdata/server.xml"));
- } catch (Exception e) {
- throw new ConfigurationException(e.getMessage());
- }
- try {
- platformConfig = new PlatformConfiguration(ConfigurationLoader.loadFile("src/testdata/platform.xml")) {};
- } catch (Exception e) {
- throw new ConfigurationException(e.getMessage());
- }
- }
-
- @Override
- public boolean isConfigurationAvailable(@SuppressWarnings("rawtypes") Class cls) {
- try {
- getConfiguration(cls);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- @Override
- public Object getConfiguration(@SuppressWarnings("rawtypes") Class cls) throws ConfigurationException {
- if (ServerConfiguration.class.equals(cls)) {
- return serverConfig;
- } else if (PlatformConfiguration.class.equals(cls)) {
- return platformConfig;
- } else {
- throw new ConfigurationException(cls.getName()
- + " configuration not available");
- }
- }
- };
-// context.setServerConfigurationResource("src/testdata/server.xml");
-// context.setPlatformConfigurationResource("src/testdata/platform.xml");
try {
- ConfigurationLoader.initialize(false, context);
+ ConfigurationLoader.initialize(false, context = new TestXmlServerConfigurationContext());
} catch (ConfigurationException e1) {
fail("Failed to initialize server configuration");
}
@@ -128,7 +87,7 @@ public class TestJschSftpProtocol extend
}
public void testCDandPWDandLS() throws IOException, ProtocolException {
- JschSftpProtocol sftpProtocol = new JschSftpProtocol(serverConfig.getPort());
+ JschSftpProtocol sftpProtocol = new JschSftpProtocol(context.getPort());
sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
new File("src/testdata/sample-dsa.pub").getAbsoluteFile()
.getAbsolutePath()));
@@ -148,7 +107,7 @@ public class TestJschSftpProtocol extend
}
public void testGET() throws ProtocolException, IOException {
- JschSftpProtocol sftpProtocol = new JschSftpProtocol(serverConfig.getPort());
+ JschSftpProtocol sftpProtocol = new JschSftpProtocol(context.getPort());
sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
new File("src/testdata/sample-dsa.pub").getAbsoluteFile()
.getAbsolutePath()));
@@ -169,7 +128,8 @@ public class TestJschSftpProtocol extend
int commandPort = -1;
int port = -1;
- public TestServerConfiguration(InputStream is) throws SAXException, ParserConfigurationException, IOException {
+ public TestServerConfiguration(InputStream is) throws SAXException,
+ ParserConfigurationException, IOException {
super(is);
}
@@ -191,4 +151,54 @@ public class TestJschSftpProtocol extend
}
}
}
+
+ private class TestXmlServerConfigurationContext extends XmlServerConfigurationContext {
+
+ private TestServerConfiguration serverConfig;
+ private PlatformConfiguration platformConfig;
+
+ public TestXmlServerConfigurationContext() {
+ super();
+ }
+
+ @Override
+ public void initialize() throws ConfigurationException {
+ try {
+ serverConfig = new TestServerConfiguration(ConfigurationLoader.loadFile("src/testdata/server.xml"));
+ } catch (Exception e) {
+ throw new ConfigurationException(e.getMessage());
+ }
+ try {
+ platformConfig = new PlatformConfiguration(ConfigurationLoader.loadFile("src/testdata/platform.xml")) {};
+ } catch (Exception e) {
+ throw new ConfigurationException(e.getMessage());
+ }
+ }
+
+ @Override
+ public boolean isConfigurationAvailable(@SuppressWarnings("rawtypes") Class cls) {
+ try {
+ getConfiguration(cls);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ @Override
+ public Object getConfiguration(@SuppressWarnings("rawtypes") Class cls) throws ConfigurationException {
+ if (ServerConfiguration.class.equals(cls)) {
+ return serverConfig;
+ } else if (PlatformConfiguration.class.equals(cls)) {
+ return platformConfig;
+ } else {
+ throw new ConfigurationException(cls.getName()
+ + " configuration not available");
+ }
+ }
+
+ public int getPort() {
+ return serverConfig.getPort();
+ }
+ }
}