Commit bcb8a800 authored by Joe Osborn's avatar Joe Osborn
Browse files

Update tests to use TestDataPath


Signed-off-by: Joe Osborn's avatarJoe Osborn <osbornjd@ornl.gov>
parent e99462f5
......@@ -17,8 +17,13 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.eclipse.ice</groupId>
<artifactId>org.eclipse.ice.tests.data</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
......
......@@ -40,6 +40,9 @@ public class EmailUpdateHandler implements ICommandUpdateHandler {
// Text file credential handler for sender's email creds
TxtFileConnectionAuthorizationHandler credHandler;
/// Mail port to email over, depends on client
private String mailPort = "25";
/**
* Default constructor
......@@ -55,7 +58,7 @@ public class EmailUpdateHandler implements ICommandUpdateHandler {
// Create some properties and setup the default
// server properties
Properties properties = System.getProperties();
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.port", mailPort);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true"); // TLS
// Setup mail server
......@@ -69,6 +72,7 @@ public class EmailUpdateHandler implements ICommandUpdateHandler {
String.valueOf(credHandler.getPassword()));
}
});
// Set session to debug just to be explicit
session.setDebug(true);
......@@ -120,5 +124,13 @@ public class EmailUpdateHandler implements ICommandUpdateHandler {
public void setMessage(String message) {
this.emailText = message;
}
/**
* Setter for mail port that depends on email client used
* @param mailPort
*/
public void setMailPort(String mailPort) {
this.mailPort = mailPort;
}
}
......@@ -63,6 +63,7 @@ public class TxtFileConnectionAuthorizationHandler extends ConnectionAuthorizati
try (Scanner scanner = new Scanner(credFile)) {
// Skip the username since it has already been set
username = scanner.next();
// Get the password
char[] pwd = scanner.next().toCharArray();
return pwd;
......
......@@ -12,7 +12,6 @@
package org.eclipse.ice.tests.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
......@@ -37,6 +36,7 @@ import org.eclipse.ice.commands.LocalFileHandler;
import org.eclipse.ice.commands.RemoteCommand;
import org.eclipse.ice.commands.RemoteFileHandler;
import org.eclipse.ice.commands.TxtFileConnectionAuthorizationHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
......@@ -179,13 +179,17 @@ public class CommandFactoryTest {
// This is the connection where the job will be executed
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String keyPath = System.getProperty("user.home") + "/.ssh/somekey";
TestDataPath keyDataPath = new TestDataPath();
String keyPath = keyDataPath.resolve("commands/somekey").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("keypath",
keyPath);
auth.setHostname("hostname");
auth.setUsername("password");
// Set it
ConnectionConfiguration firstConn = new ConnectionConfiguration();
firstConn.setAuthorization(auth);
......@@ -196,9 +200,9 @@ public class CommandFactoryTest {
firstConn.deleteWorkingDirectory(false);
ConnectionConfiguration secondConn = new ConnectionConfiguration();
String credFile = "/tmp/ice-remote-creds.txt";
if(System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler intermAuth = authFactory.getConnectionAuthorizationHandler("text",credFile);
secondConn.setAuthorization(intermAuth);
......@@ -692,9 +696,9 @@ public class CommandFactoryTest {
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
cfg.setAuthorization(auth);
......
......@@ -25,6 +25,7 @@ import org.eclipse.ice.commands.EmailUpdateHandler;
import org.eclipse.ice.commands.HTTPCommandUpdateHandler;
import org.eclipse.ice.commands.ICommandUpdateHandler;
import org.eclipse.ice.commands.TxtFileConnectionAuthorizationHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.Test;
/**
......@@ -147,15 +148,14 @@ public class CommandFactoryUpdaterTest {
*/
private EmailUpdateHandler setupEmailUpdateHandler() {
// Get a text file with credentials
String credFile = "/tmp/email-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\email-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-email-creds.txt").toString();
TxtFileConnectionAuthorizationHandler auth = new TxtFileConnectionAuthorizationHandler();
auth.setOption(credFile);
EmailUpdateHandler handler = new EmailUpdateHandler();
handler.setCredHandler(auth);
handler.setMailPort("587");
return handler;
}
}
......@@ -30,6 +30,7 @@ import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.commands.LocalCommand;
import org.eclipse.ice.commands.RemoteCommand;
import org.eclipse.ice.commands.TxtFileConnectionAuthorizationHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -118,21 +119,25 @@ public class CommandTest {
commandConfig.setAppendInput(true); // append the input file name to the script executable command
commandConfig.setNumProcs("1"); // number of processes is 1
commandConfig.setOS(System.getProperty("os.name"));
// Set the remote working directory, where the command will be processed
commandConfig.setRemoteWorkingDirectory("/tmp/remoteCommandTestDirectory");
// Set the connection configuration to a dummy remote connection
// Make the ConnectionConfiguration and set it up
ConnectionConfiguration connectConfig = new ConnectionConfiguration();
// Make the connection configuration
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
connectConfig.setAuthorization(auth);
connectConfig.setName("dummyConnection");
......@@ -160,18 +165,21 @@ public class CommandTest {
public void testLocalCommand() {
System.out.println("\n\n\n\nTest a local command!");
String os = System.getProperty("os.name");
// Set the CommandConfiguration class
// See {@link org.eclipse.ice.commands.CommandConfiguration} for detailed info
// on each
CommandConfiguration commandConfig = new CommandConfiguration();
commandConfig.setCommandId(1);
commandConfig.setExecutable("./test_code_execution.sh");
// If the os is windows, set the executable appropriately
if (os.toLowerCase().contains("win")) {
// two slashes so that java doesn't read it as a tab
commandConfig.setExecutable(".\\test_code_execution.ps1");
commandConfig.setInterpreter("powershell.exe");
}
commandConfig.addInputFile("someInputFile", "someInputFile.txt");
commandConfig.setErrFileName("someLocalErrFile.txt");
commandConfig.setOutFileName("someLocalOutFile.txt");
......@@ -226,14 +234,16 @@ public class CommandTest {
// Make the ConnectionConfiguration and set it up
ConnectionConfiguration connectConfig = new ConnectionConfiguration();
// Make the connection configuration
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
connectConfig.setAuthorization(auth);
......@@ -292,14 +302,16 @@ public class CommandTest {
public void testArgumentCommand() {
// Make the ConnectionConfiguration and set it up
ConnectionConfiguration connectConfig = new ConnectionConfiguration();
// Make the connection configuration
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
connectConfig.setAuthorization(auth);
......
......@@ -25,6 +25,7 @@ import org.eclipse.ice.commands.ConnectionAuthorizationHandler;
import org.eclipse.ice.commands.ConnectionAuthorizationHandlerFactory;
import org.eclipse.ice.commands.ConnectionConfiguration;
import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.Test;
/**
......@@ -67,9 +68,8 @@ public class ConnectionAuthorizationHandlerFactoryTest {
*/
@Test
public void testTextAuthorization() throws IOException {
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
// Get a text file authorization handler
ConnectionAuthorizationHandler text = factory.getConnectionAuthorizationHandler("text", credFile);
......@@ -114,9 +114,8 @@ public class ConnectionAuthorizationHandlerFactoryTest {
// Create a text file credential path to get the same username/hostname
// as the key, in the event someone is using a host that is not the dummy
// server
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
// Get a text file authorization handler
ConnectionAuthorizationHandler text = factory.getConnectionAuthorizationHandler("text", credFile);
......
......@@ -27,6 +27,7 @@ import org.eclipse.ice.commands.ConnectionConfiguration;
import org.eclipse.ice.commands.ConnectionManager;
import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.commands.KeyPathConnectionAuthorizationHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
......@@ -73,9 +74,8 @@ public class ConnectionManagerTest {
// Request a ConnectionAuthorization of type text file which contains the
// credentials
ConnectionAuthorizationHandler auth = null;
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
......@@ -218,9 +218,8 @@ public class ConnectionManagerTest {
ConnectionManager manager = ConnectionManagerFactory.getConnectionManager();
// Read in a dummy configuration file that contains credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
// Set the credentials since they were deleted after closing the previous
// connection
......@@ -322,9 +321,8 @@ public class ConnectionManagerTest {
ConnectionManager manager = ConnectionManagerFactory.getConnectionManager();
// Read in a dummy configuration file that contains credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
import org.eclipse.ice.commands.EmailUpdateHandler;
import org.eclipse.ice.commands.TxtFileConnectionAuthorizationHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.Test;
/**
......@@ -39,10 +40,9 @@ public class EmailHandlerTest {
public void testEmailNotificationPostUpdate() {
// Get a text file with credentials
String credFile = "/tmp/email-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\email-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-email-creds.txt").toString();
TxtFileConnectionAuthorizationHandler handler = new TxtFileConnectionAuthorizationHandler();
handler.setOption(credFile);
......@@ -51,6 +51,7 @@ public class EmailHandlerTest {
updater.setCredHandler(handler);
updater.setMessage("This is a test updater");
updater.setSubject("This is a test subject");
updater.setMailPort("587"); // gmail mail port
try {
updater.postUpdate();
} catch (IOException e) {
......
......@@ -25,6 +25,7 @@ import org.eclipse.ice.commands.ConnectionConfiguration;
import org.eclipse.ice.commands.ConnectionManager;
import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.commands.RemoteCommand;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
......@@ -93,12 +94,12 @@ public class RemoteCommandTest {
// Make the connection configuration
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win")) {
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
}
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
connectConfig.setAuthorization(auth);
......@@ -159,7 +160,7 @@ public class RemoteCommandTest {
@Test
public void testRemoteCommand() {
System.out.println("Testing remote command configuration");
// Get a command which just sets everything up
RemoteCommand command = new RemoteCommand(commandConfig, connectConfig, null);
......@@ -223,10 +224,9 @@ public class RemoteCommandTest {
badConfig.setOS(System.getProperty("os.name"));
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win")) {
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
}
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
ConnectionConfiguration cfg = new ConnectionConfiguration();
......
......@@ -37,6 +37,7 @@ import org.eclipse.ice.commands.ConnectionManager;
import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.commands.RemoteFileBrowser;
import org.eclipse.ice.commands.RemoteFileHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -308,13 +309,15 @@ public class RemoteFileBrowserTest {
private static ConnectionConfiguration makeConnectionConfiguration() {
// Set the connection configuration to a dummy remote connection
ConnectionConfiguration config = new ConnectionConfiguration();
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
config.setAuthorization(auth);
......
......@@ -39,6 +39,7 @@ import org.eclipse.ice.commands.ConnectionConfiguration;
import org.eclipse.ice.commands.ConnectionManager;
import org.eclipse.ice.commands.ConnectionManagerFactory;
import org.eclipse.ice.commands.RemoteFileHandler;
import org.eclipse.ice.tests.data.TestDataPath;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -295,13 +296,15 @@ public class RemoteFileHandlerTest {
private static ConnectionConfiguration makeConnectionConfiguration() {
// Set the connection configuration to a dummy remote connection
ConnectionConfiguration config = new ConnectionConfiguration();
// Get a factory which determines the type of authorization
// Get a factory which determines the type of authorization
ConnectionAuthorizationHandlerFactory authFactory = new ConnectionAuthorizationHandlerFactory();
// Request a ConnectionAuthorization of type text file which contains the
// credentials
String credFile = "/tmp/ice-remote-creds.txt";
if (System.getProperty("os.name").toLowerCase().contains("win"))
credFile = "C:\\Users\\Administrator\\ice-remote-creds.txt";
TestDataPath dataPath = new TestDataPath();
String credFile = dataPath.resolve("commands/ice-remote-creds.txt").toString();
ConnectionAuthorizationHandler auth = authFactory.getConnectionAuthorizationHandler("text", credFile);
// Set it
config.setAuthorization(auth);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment