mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
11.38.2014 28e71da73154f5e4c4d0d18021431e50a84c6bc2
opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/SetupCliTestCase.java
@@ -58,6 +58,9 @@
                "--adminConnectorPort", "4444",
                "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
                "-a"), expectedErrOutput(LocalizableMessage.EMPTY) },
            { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
                    "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
                    "-a", "--ldapsPort", "1636", "--generateSelfSignedCertificate"), null },
        };
        return data;
    }
@@ -79,8 +82,13 @@
        Object[][] data = new Object[][] {
            { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
                    "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
                    "-a"),
                null },
                    "-a"), null },
            { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
                    "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
                    "-a", "--ldapsPort", "1636"), null },
            { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
                    "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
                    "-a", "--jmxPort", "1689"), null },
        };
        return data;
    }
@@ -158,10 +166,21 @@
                assertThat(resultCode).isEqualTo(ReturnCode.SUCCESS.get());
            } else {
                assertThat(resultCode).isNotEqualTo(ReturnCode.SUCCESS.get());
                assertThat(err.size()).isGreaterThan(0);
                final String errorMsg = err.toString("UTF-8").replaceAll(Utils.LINE_SEPARATOR, " ");
                final String expectedMsg = expectedErrOutput.toString().replaceAll(Utils.LINE_SEPARATOR, " ");
                assertTrue(errorMsg.contains(expectedMsg), errorMsg + "\n >---< \n" + expectedMsg);
                String errMsg = null;
                String expectedMsg = getUnWrappedMessage(expectedErrOutput.toString());
                /**
                 * If an application is interactive, all messages should be redirect to the stdout. (info, warnings,
                 * errors). Otherwise, standard messages should be displayed in the stdout(info) and errors to the
                 * stderr (warnings, errors).
                 */
                if (setup.isInteractive()) {
                    assertThat(out.size()).isGreaterThan(0);
                    errMsg = getUnWrappedMessage(out.toString("UTF-8"));
                } else {
                    assertThat(err.size()).isGreaterThan(0);
                    errMsg = getUnWrappedMessage(err.toString("UTF-8"));
                }
                assertTrue(errMsg.contains(expectedMsg), errMsg + "\n >---< \n" + expectedMsg);
            }
        } finally {
            closeSilently(outStream, errStream);
@@ -177,4 +196,15 @@
    private LocalizableMessage expectedErrOutput(LocalizableMessage val) {
        return val;
    }
    /**
     * Returns the message to its unwrapped form.
     *
     * @param st
     *            The message which need to be unwrapped.
     * @return The unwrapped message.
     */
    private String getUnWrappedMessage(final String st) {
        return st.replaceAll(Utils.LINE_SEPARATOR, " ");
    }
}