* Test for passing runtime context.
* @throws Exception if failed
*/
@Test
public void inherit_context() throws Exception {
RuntimeContext context = RuntimeContext.DEFAULT
.mode(ExecutionMode.SIMULATION)
.batchId("testbatch")
.buildId("testverify");
RuntimeContext.set(context);
putScript(target, "libexec/check-context.sh", SshProfile.COMMAND_GET);
Map<String, String> results = new HashMap<String, String>();
JschConnection conn = new JschConnection(profile, Arrays.asList(profile.getGetCommand()));
try {
InputStream output = conn.openStandardOutput();
conn.connect();
Scanner s = new Scanner(output, "UTF-8");
while (s.hasNextLine()) {
String[] pair = s.nextLine().split("=", 2);
if (pair.length == 2) {
results.put(pair[0], pair[1]);
}
}
s.close();
int exit = conn.waitForExit(10000);
assertThat(exit, is(0));
} finally {
conn.close();
}
RuntimeContext restored = RuntimeContext.DEFAULT.apply(results);
assertThat(results.toString(), restored, is(context));
}