Created
March 5, 2012 16:12
-
-
Save iocanel/1979051 to your computer and use it in GitHub Desktop.
Creating a method for invoking Karaf shell from inside a pax-exam karaf unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject | |
CommandProcessor commandProcessor; | |
protected String executeCommands(final String ...commands) { | |
String response; | |
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | |
final PrintStream printStream = new PrintStream(byteArrayOutputStream); | |
final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err); | |
FutureTask<string> commandFuture = new FutureTask<string>( | |
new Callable<string>() { | |
public String call() { | |
try { | |
for(String command:commands) { | |
System.err.println(command); | |
commandSession.execute(command); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(System.err); | |
} | |
return byteArrayOutputStream.toString(); | |
} | |
}); | |
try { | |
executor.submit(commandFuture); | |
response = commandFuture.get(COMMAND_TIMEOUT, TimeUnit.MILLISECONDS); | |
} catch (Exception e) { | |
e.printStackTrace(System.err); | |
response = "SHELL COMMAND TIMED OUT: "; | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment