From edb7b32eaa2db4a171496d30ed3293bfa06b30c8 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Tue, 11 Feb 2014 13:36:41 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1303 - added DEFAULT_LDAP_CONNECT_TIMEOUT to constants. - added ClientException, merge it with CLIException. Replaced CLIException calls. (CLIException will disappear soon) - Console application : errors,warnings should be displayed in stdout if interactive mode is enabled. 	- added unit tests. 	- removed closeIfNotNull / replaced it by Utils.closeSilently

---
 opendj-cli/src/test/java/com/forgerock/opendj/cli/ConsoleApplicationTestCase.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/opendj-cli/src/test/java/com/forgerock/opendj/cli/ConsoleApplicationTestCase.java b/opendj-cli/src/test/java/com/forgerock/opendj/cli/ConsoleApplicationTestCase.java
index f22ad43..f0aa277 100644
--- a/opendj-cli/src/test/java/com/forgerock/opendj/cli/ConsoleApplicationTestCase.java
+++ b/opendj-cli/src/test/java/com/forgerock/opendj/cli/ConsoleApplicationTestCase.java
@@ -33,6 +33,8 @@
 import org.testng.annotations.Test;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 /**
  * Unit tests for the console application class.
@@ -80,8 +82,12 @@
             return interactive;
         }
 
-        public void setVerbose(boolean verbose) {
-            this.verbose = verbose;
+        public void setVerbose(boolean v) {
+            verbose = v;
+        }
+
+        public void setInteractive(boolean inter) {
+            interactive = inter;
         }
     }
 
@@ -99,7 +105,7 @@
     public void testWriteLineInErrorStream() throws UnsupportedEncodingException {
         final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings.");
         final MockConsoleApplication ca = MockConsoleApplication.getDefault();
-        ca.errPrint(msg);
+        ca.errPrintln(msg);
         assertThat(ca.getOut()).isEmpty();
         assertThat(ca.getErr()).contains(msg.toString());
     }
@@ -134,4 +140,50 @@
         assertThat(ca.getOut()).isEmpty();
         assertThat(ca.getErr()).contains(msg.toString());
     }
+
+    /**
+     * In non interactive applications, standard messages should be displayed in the stdout(info) and errors to the
+     * stderr (warnings, errors).
+     *
+     * @throws UnsupportedEncodingException
+     */
+    @Test()
+    public void testNonInteractiveApplicationShouldNotStdoutErrors() throws UnsupportedEncodingException {
+        final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings.");
+        final LocalizableMessage msg2 = LocalizableMessage
+                .raw("If somebody wants a sheep, that is a proof that one exists.");
+        final MockConsoleApplication ca = MockConsoleApplication.getDefault();
+
+        assertFalse(ca.isInteractive());
+        ca.errPrintln(msg);
+        assertThat(ca.getOut()).isEmpty();
+        assertThat(ca.getErr()).contains(msg.toString());
+        ca.println(msg2);
+        assertThat(ca.getOut()).contains(msg2.toString());
+        assertThat(ca.getErr()).doesNotContain(msg2.toString());
+    }
+
+    /**
+     * If an application is interactive, all messages should be redirect to the stdout. (info, warnings, errors).
+     *
+     * @throws UnsupportedEncodingException
+     */
+    @Test()
+    public void testInteractiveApplicationShouldStdoutErrors() throws UnsupportedEncodingException {
+        final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings.");
+        final LocalizableMessage msg2 = LocalizableMessage
+                .raw("If somebody wants a sheep, that is a proof that one exists.");
+
+        final MockConsoleApplication ca = MockConsoleApplication.getDefault();
+
+        assertFalse(ca.isInteractive());
+        ca.setInteractive(true);
+        assertTrue(ca.isInteractive());
+        ca.errPrintln(msg);
+        assertThat(ca.getOut()).contains(msg.toString());
+        assertThat(ca.getErr()).isEmpty();
+        ca.println(msg2);
+        assertThat(ca.getOut()).contains(msg2.toString());
+        assertThat(ca.getErr()).isEmpty();
+    }
 }

--
Gitblit v1.10.0