use of io.pravega.cli.admin.AdminCommand in project pravega by pravega.
the class TestUtils method executeCommand.
/**
* Invoke any command and get the result by using a mock PrintStream object (instead of System.out). The returned
* String is the output written by the Command that can be check in any test.
*
* @param inputCommand Command to execute.
* @param state Configuration to execute the command.
* @return Output of the command.
* @throws Exception If a problem occurs.
*/
public static String executeCommand(String inputCommand, AdminCommandState state) throws Exception {
Parser.Command pc = Parser.parse(inputCommand);
CommandArgs args = new CommandArgs(pc.getArgs(), state);
AdminCommand cmd = AdminCommand.Factory.get(pc.getComponent(), pc.getName(), args);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8)) {
cmd.setOut(ps);
cmd.execute();
}
return baos.toString(StandardCharsets.UTF_8);
}
Aggregations