// Path: test-utils/src/main/java/com/ibm/ws/lars/testutils/FatUtils.java
// public class FatUtils {
// 
//     public static final String SCRIPT;
// 
//     public static final String DB_PORT;
//     public static final String LIBERTY_PORT_HTTP;
//     public static final String LIBERTY_PORT_HTTPS;
//     public static final String TEST_DB_NAME;
//     public static final String LARS_APPLICATION_ROOT;
//     public static final String BASEURL_LIBERTY_PORT_HTTP;
// 
//     static {
//         if (System.getProperty("os.name").startsWith("Windows")) {
//             SCRIPT = "client/bin/larsClient.bat";
//         } else {
//             SCRIPT = "client/bin/larsClient";
//         }
// 
//         Properties defaultConfig = new Properties();
//         InputStream propsStream = FatUtils.class.getClassLoader().getResourceAsStream("config.properties");
//         try {
//             defaultConfig.load(propsStream);
//         } catch (IOException e) {
//             // Can't recover from this
//             throw new RuntimeException("Unable to find config.properties file for database/server configuration");
//         }
// 
//         DB_PORT = defaultConfig.getProperty("testMongoPort");
//         LIBERTY_PORT_HTTP = defaultConfig.getProperty("testLibertyPortHTTP");
//         LIBERTY_PORT_HTTPS = defaultConfig.getProperty("testLibertyPortHTTPS");
//         TEST_DB_NAME = defaultConfig.getProperty("testDbName");
//         LARS_APPLICATION_ROOT = defaultConfig.getProperty("larsApplicationRoot");
//         BASEURL_LIBERTY_PORT_HTTP = defaultConfig.getProperty("baseUrlLibertyPortHTTP");
// 
//     }
// 
//     public static final String SERVER_URL = "http://localhost:" + LIBERTY_PORT_HTTP + LARS_APPLICATION_ROOT;
// 
//     public static final String DEFAULT_HOST_AND_PORT = "localhost:" + DB_PORT;
// 
//     public static final String ADMIN_USERNAME = "admin";
// 
//     public static final String ADMIN_PASSWORD = "passw0rd";
// 
//     public static final String USER_ROLE_USERNAME = "user";
// 
//     public static final String USER_ROLE_PASSWORD = "passw0rd";
// 
//     public static final String BASEURL_SERVER_URL = "http://localhost:" + BASEURL_LIBERTY_PORT_HTTP + LARS_APPLICATION_ROOT;
// 
//     public static final RepositoryFixture FAT_REPO = LarsRepositoryFixture.createFixture(SERVER_URL, "1", ADMIN_USERNAME, ADMIN_PASSWORD, USER_ROLE_USERNAME, USER_ROLE_PASSWORD);
// 
//     private static DB fatDB = null;
// 
//     public static int countLines(String input) {
//         int lines = 0;
//         // If the last character isn't \n, add one, as that will make
//         // the count match what you would normally expect
//         if (input.charAt(input.length() - 1) != '\n') {
//             lines = 1;
//         }
//         while (true) {
//             int nlIndex = input.indexOf('\n');
//             if (nlIndex == -1) {
//                 break;
//             }
//             lines++;
//             input = input.substring(nlIndex + 1);
//         }
//         return lines;
//     }
// 
//     public static Object[][] getRestFixtureParameters() {
//         List<Object[]> objectList = new ArrayList<Object[]>();
// 
//         objectList.add(new Object[] { FAT_REPO });
// 
//         return objectList.toArray(new Object[objectList.size()][]);
//     }
// 
//     /**
//      * Returns a connection to the mongo database used for fat tests.
//      * <p>
//      * The same connection instance is returned to all tests.
//      * <p>
//      * We never explicitly close the client and rely on the connection being closed when the JVM
//      * exits.
//      */
//     public static synchronized DB getMongoDB() throws UnknownHostException {
//         if (fatDB == null) {
//             MongoClient mongoClient = new MongoClient("localhost:" + FatUtils.DB_PORT, new MongoClientOptions.Builder().build());
//             fatDB = mongoClient.getDB(FatUtils.TEST_DB_NAME);
//         }
//         return fatDB;
//     }
// }


import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.junit.Test;
import com.ibm.ws.lars.testutils.FatUtils;

        public MainRunner(String expectedExceptionMessage, int expectedStdoutLines) {
            this.expectedExceptionMessage = expectedExceptionMessage;
            this.expectedStdoutLines = expectedStdoutLines;
        }

        public void run(String... args) throws ClientException {
            InputStream input = new ByteArrayInputStream(new byte[0]);
            ByteArrayOutputStream stdoutBAOS = new ByteArrayOutputStream();
            try (PrintStream output = new PrintStream(stdoutBAOS)) {
                Main main = new Main(input, output);
                Exception exception = null;
                try {
                    main.run(args);
                } catch (ClientException e) {
                    if (expectedExceptionMessage != null) {
                        exception = e;
                        assertEquals("Unexpected exception message", expectedExceptionMessage, e.getMessage());
                    } else {
                        throw e;
                    }
                }
                if (expectedExceptionMessage != null && exception == null) {
                    fail("The expected client exception was not thrown");
                }

                stdout = stdoutBAOS.toString();

                assertEquals("The help output didn't contain the expected number of lines:\n" + stdout,
                             expectedStdoutLines,
// Path: test-utils/src/main/java/com/ibm/ws/lars/testutils/FatUtils.java
// public class FatUtils {
// 
//     public static final String SCRIPT;
// 
//     public static final String DB_PORT;
//     public static final String LIBERTY_PORT_HTTP;
//     public static final String LIBERTY_PORT_HTTPS;
//     public static final String TEST_DB_NAME;
//     public static final String LARS_APPLICATION_ROOT;
//     public static final String BASEURL_LIBERTY_PORT_HTTP;
// 
//     static {
//         if (System.getProperty("os.name").startsWith("Windows")) {
//             SCRIPT = "client/bin/larsClient.bat";
//         } else {
//             SCRIPT = "client/bin/larsClient";
//         }
// 
//         Properties defaultConfig = new Properties();
//         InputStream propsStream = FatUtils.class.getClassLoader().getResourceAsStream("config.properties");
//         try {
//             defaultConfig.load(propsStream);
//         } catch (IOException e) {
//             // Can't recover from this
//             throw new RuntimeException("Unable to find config.properties file for database/server configuration");
//         }
// 
//         DB_PORT = defaultConfig.getProperty("testMongoPort");
//         LIBERTY_PORT_HTTP = defaultConfig.getProperty("testLibertyPortHTTP");
//         LIBERTY_PORT_HTTPS = defaultConfig.getProperty("testLibertyPortHTTPS");
//         TEST_DB_NAME = defaultConfig.getProperty("testDbName");
//         LARS_APPLICATION_ROOT = defaultConfig.getProperty("larsApplicationRoot");
//         BASEURL_LIBERTY_PORT_HTTP = defaultConfig.getProperty("baseUrlLibertyPortHTTP");
// 
//     }
// 
//     public static final String SERVER_URL = "http://localhost:" + LIBERTY_PORT_HTTP + LARS_APPLICATION_ROOT;
// 
//     public static final String DEFAULT_HOST_AND_PORT = "localhost:" + DB_PORT;
// 
//     public static final String ADMIN_USERNAME = "admin";
// 
//     public static final String ADMIN_PASSWORD = "passw0rd";
// 
//     public static final String USER_ROLE_USERNAME = "user";
// 
//     public static final String USER_ROLE_PASSWORD = "passw0rd";
// 
//     public static final String BASEURL_SERVER_URL = "http://localhost:" + BASEURL_LIBERTY_PORT_HTTP + LARS_APPLICATION_ROOT;
// 
//     public static final RepositoryFixture FAT_REPO = LarsRepositoryFixture.createFixture(SERVER_URL, "1", ADMIN_USERNAME, ADMIN_PASSWORD, USER_ROLE_USERNAME, USER_ROLE_PASSWORD);
// 
//     private static DB fatDB = null;
// 
//     public static int countLines(String input) {
//         int lines = 0;
//         // If the last character isn't \n, add one, as that will make
//         // the count match what you would normally expect
//         if (input.charAt(input.length() - 1) != '\n') {
//             lines = 1;
//         }
//         while (true) {
//             int nlIndex = input.indexOf('\n');
//             if (nlIndex == -1) {
//                 break;
//             }
//             lines++;
//             input = input.substring(nlIndex + 1);
//         }
//         return lines;
//     }
// 
//     public static Object[][] getRestFixtureParameters() {
//         List<Object[]> objectList = new ArrayList<Object[]>();
// 
//         objectList.add(new Object[] { FAT_REPO });
// 
//         return objectList.toArray(new Object[objectList.size()][]);
//     }
// 
//     /**
//      * Returns a connection to the mongo database used for fat tests.
//      * <p>
//      * The same connection instance is returned to all tests.
//      * <p>
//      * We never explicitly close the client and rely on the connection being closed when the JVM
//      * exits.
//      */
//     public static synchronized DB getMongoDB() throws UnknownHostException {
//         if (fatDB == null) {
//             MongoClient mongoClient = new MongoClient("localhost:" + FatUtils.DB_PORT, new MongoClientOptions.Builder().build());
//             fatDB = mongoClient.getDB(FatUtils.TEST_DB_NAME);
//         }
//         return fatDB;
//     }
// }


// Path: cli-client/src/test/java/com/ibm/ws/lars/upload/cli/MainTest.java
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.junit.Test;
import com.ibm.ws.lars.testutils.FatUtils;


        public MainRunner(String expectedExceptionMessage, int expectedStdoutLines) {
            this.expectedExceptionMessage = expectedExceptionMessage;
            this.expectedStdoutLines = expectedStdoutLines;
        }

        public void run(String... args) throws ClientException {
            InputStream input = new ByteArrayInputStream(new byte[0]);
            ByteArrayOutputStream stdoutBAOS = new ByteArrayOutputStream();
            try (PrintStream output = new PrintStream(stdoutBAOS)) {
                Main main = new Main(input, output);
                Exception exception = null;
                try {
                    main.run(args);
                } catch (ClientException e) {
                    if (expectedExceptionMessage != null) {
                        exception = e;
                        assertEquals("Unexpected exception message", expectedExceptionMessage, e.getMessage());
                    } else {
                        throw e;
                    }
                }
                if (expectedExceptionMessage != null && exception == null) {
                    fail("The expected client exception was not thrown");
                }

                stdout = stdoutBAOS.toString();

                assertEquals("The help output didn't contain the expected number of lines:\n" + stdout,
                             expectedStdoutLines,
                             FatUtils.countLines(stdout));