|
@@ -19,7 +19,9 @@ package org.apache.zookeeper;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.PrintStream;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
@@ -344,4 +346,25 @@ public class ZooKeeperTest extends ClientBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testCliCommandsNotEchoingUsage() throws Exception {
|
|
|
+ // setup redirect out/err streams to get System.in/err, use this judiciously!
|
|
|
+ final PrintStream systemErr = System.err; // get current err
|
|
|
+ final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
|
|
+ System.setErr(new PrintStream(errContent));
|
|
|
+ final ZooKeeper zk = createClient();
|
|
|
+ ZooKeeperMain zkMain = new ZooKeeperMain(zk);
|
|
|
+ String cmd1 = "printwatches";
|
|
|
+ zkMain.executeLine(cmd1);
|
|
|
+ String cmd2 = "history";
|
|
|
+ zkMain.executeLine(cmd2);
|
|
|
+ String cmd3 = "redo";
|
|
|
+ zkMain.executeLine(cmd3);
|
|
|
+ // revert redirect of out/err streams - important step!
|
|
|
+ System.setErr(systemErr);
|
|
|
+ if (errContent.toString().contains("ZooKeeper -server host:port cmd args")) {
|
|
|
+ fail("CLI commands (history, redo, connect, printwatches) display usage info!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|