From de7fb4f670a30ec3da2ec0ee693c1714e26b248a Mon Sep 17 00:00:00 2001 From: Jarek Jarcec Cecho Date: Thu, 10 Dec 2015 12:34:04 +0100 Subject: [PATCH] SQOOP-2717: Sqoop2: Use connector name in shell (Colin Ma via Jarek Jarcec Cecho) --- .../sqoop/shell/CreateLinkFunction.java | 35 +++++-------------- .../sqoop/shell/ShowConnectorFunction.java | 32 +++++++---------- .../apache/sqoop/shell/ShowJobFunction.java | 14 ++++---- .../apache/sqoop/shell/ShowLinkFunction.java | 6 ++-- .../apache/sqoop/shell/core/Constants.java | 24 ++++++------- .../main/resources/shell-resource.properties | 13 ++++--- .../apache/sqoop/shell/TestCreateCommand.java | 20 ++--------- .../apache/sqoop/shell/TestShowCommand.java | 16 ++++----- 8 files changed, 55 insertions(+), 105 deletions(-) diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateLinkFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateLinkFunction.java index e5af3f18..77bfabcd 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/CreateLinkFunction.java +++ b/shell/src/main/java/org/apache/sqoop/shell/CreateLinkFunction.java @@ -46,11 +46,11 @@ public class CreateLinkFunction extends SqoopFunction { @SuppressWarnings("static-access") public CreateLinkFunction() { this.addOption(OptionBuilder - .withDescription(resourceString(Constants.RES_CONNECTOR_ID)) - .withLongOpt(Constants.OPT_CID) + .withDescription(resourceString(Constants.RES_CONNECTOR_NAME)) + .withLongOpt(Constants.OPT_CONNECTOR_NAME) .isRequired() .hasArg() - .create(Constants.OPT_CID_CHAR)); + .create(Constants.OPT_CONNECTOR_NAME_CHAR)); } @Override @@ -60,31 +60,12 @@ public Object executeFunction(CommandLine line, boolean isInteractive) throws IO } private Status createLink(CommandLine line, List args, boolean isInteractive) throws IOException { + String connectorName = line.getOptionValue(Constants.OPT_CONNECTOR_NAME); - //Check if the command argument is a connector name - MLink link = null; - Long cid; - String connectorName = line.getOptionValue(Constants.OPT_CID); - MConnector connector = getClient().getConnector(connectorName); - if (null == connector) { - //Now check if command line argument is a connector id - //This works as getConnector(String...) does not throw an exception - cid = getLong(line, Constants.OPT_CID); - getClient().getConnector(cid); - - //Would have thrown an exception before this if input was an invalid connector name - //This will do an extra getConnector() call again inside createLink() - //but should not matter as connectors are cached - link = getClient().createLink(connectorName); - printlnResource(Constants.RES_CREATE_CREATING_LINK, cid); - } - else { - //Command line had connector name - //This will do an extra getConnector() call again inside createLink() but - //should not matter as connectors are cached - link = getClient().createLink(connectorName); - printlnResource(Constants.RES_CREATE_CREATING_LINK, connectorName); - } + //Command line had connector name + //This will call getConnector() inside createLink() + MLink link = getClient().createLink(connectorName); + printlnResource(Constants.RES_CREATE_CREATING_LINK, connectorName); ConsoleReader reader = getConsoleReader(); diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java index 07cccf20..d973499d 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java +++ b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java @@ -23,6 +23,8 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; +import org.apache.sqoop.client.ClientError; +import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.model.MConnector; import org.apache.sqoop.shell.core.Constants; import org.apache.sqoop.shell.utils.TableDisplayer; @@ -41,17 +43,17 @@ public ShowConnectorFunction() { .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS)) .withLongOpt(Constants.OPT_ALL) .create(Constants.OPT_ALL_CHAR)); - this.addOption(OptionBuilder.hasArg().withArgName("cid") - .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID)) - .withLongOpt(Constants.OPT_CID) - .create(Constants.OPT_CID_CHAR)); + this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_NAME) + .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_NAME)) + .withLongOpt(Constants.OPT_NAME) + .create(Constants.OPT_NAME_CHAR)); } @Override public Object executeFunction(CommandLine line, boolean isInteractive) { if (line.hasOption(Constants.OPT_ALL)) { showConnectors(); - } else if (line.hasOption(Constants.OPT_CID)) { + } else if (line.hasOption(Constants.OPT_NAME)) { showConnector(line); } else { showSummary(); @@ -64,27 +66,24 @@ private void showSummary() { Collection connectors = client.getConnectors(); List header = new LinkedList(); - header.add(resourceString(Constants.RES_TABLE_HEADER_ID)); header.add(resourceString(Constants.RES_TABLE_HEADER_NAME)); header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION)); header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS)); header.add(resourceString(Constants.RES_TABLE_HEADER_SUPPORTED_DIRECTIONS)); - List ids = new LinkedList(); List uniqueNames = new LinkedList(); List versions = new LinkedList(); List classes = new LinkedList(); List supportedDirections = new LinkedList(); for(MConnector connector : connectors) { - ids.add(String.valueOf(connector.getPersistenceId())); uniqueNames.add(connector.getUniqueName()); versions.add(connector.getVersion()); classes.add(connector.getClassName()); supportedDirections.add(connector.getSupportedDirections().toString()); } - TableDisplayer.display(header, ids, uniqueNames, versions, classes, supportedDirections); + TableDisplayer.display(header, uniqueNames, versions, classes, supportedDirections); } private void showConnectors() { @@ -99,17 +98,13 @@ private void showConnectors() { private void showConnector(CommandLine line) { //Check if the command argument is a connector name - String connectorName = line.getOptionValue(Constants.OPT_CID); + String connectorName = line.getOptionValue(Constants.OPT_NAME); MConnector connector = client.getConnector(connectorName); - if (null == connector) { - //Now check if command line argument is a connector id - //This works as getConnector(String...) does not throw an exception - Long cid = getLong(line, Constants.OPT_CID); - connector = client.getConnector(cid); - } - //No null checks here - as before. This is because getConnector(long...) - //throws an exception if connector is not found. + // check if the connector exist + if (connector == null) { + throw new SqoopException(ClientError.CLIENT_0003, connectorName); + } printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1); @@ -118,7 +113,6 @@ private void showConnector(CommandLine line) { private void displayConnector(MConnector connector) { printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO, - connector.getPersistenceId(), connector.getUniqueName(), connector.getClassName(), connector.getVersion(), diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java index 600de8b8..786cac79 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java +++ b/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java @@ -47,10 +47,10 @@ public ShowJobFunction() { .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS)) .withLongOpt(Constants.OPT_ALL) .create(Constants.OPT_ALL_CHAR)); - this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_CID) - .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOBS_CID)) - .withLongOpt(Constants.OPT_CID) - .create(Constants.OPT_CID_CHAR)); + this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_CONNECTOR_NAME) + .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOBS_CN)) + .withLongOpt(Constants.OPT_CONNECTOR_NAME) + .create(Constants.OPT_CONNECTOR_NAME_CHAR)); this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID)) .withLongOpt(Constants.OPT_JID) @@ -61,11 +61,9 @@ public ShowJobFunction() { public Object executeFunction(CommandLine line, boolean isInteractive) { if (line.hasOption(Constants.OPT_ALL)) { showJobs(null); - } else if (line.hasOption(Constants.OPT_CID)) { - //showJobs(getLong(line, Constants.OPT_CID)); - showJobs(line.getOptionValue(Constants.OPT_CID)); + } else if (line.hasOption(Constants.OPT_CONNECTOR_NAME)) { + showJobs(line.getOptionValue(Constants.OPT_CONNECTOR_NAME)); } else if (line.hasOption(Constants.OPT_JID)) { - //showJob(getLong(line, Constants.OPT_JID)); showJob(line.getOptionValue(Constants.OPT_JID)); } else { showSummary(); diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java index 663a3779..d997f739 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java +++ b/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java @@ -74,13 +74,11 @@ private void showSummary() { List header = new LinkedList(); header.add(resourceString(Constants.RES_TABLE_HEADER_ID)); header.add(resourceString(Constants.RES_TABLE_HEADER_NAME)); - header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_ID)); header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_NAME)); header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED)); List ids = new LinkedList(); List names = new LinkedList(); - List connectorIds = new LinkedList(); List connectorNames = new LinkedList(); List availabilities = new LinkedList(); @@ -91,7 +89,7 @@ private void showSummary() { availabilities.add(String.valueOf(link.getEnabled())); } - TableDisplayer.display(header, ids, names, connectorIds, connectorNames, availabilities); + TableDisplayer.display(header, ids, names, connectorNames, availabilities); } private void showLinks() { @@ -125,7 +123,7 @@ private void displayLink(MLink link) { formatter.format(link.getLastUpdateDate()) ); - printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, link.getConnectorName()); + printlnResource(Constants.RES_SHOW_PROMPT_LINK_CN_INFO, link.getConnectorName()); // Display link config displayConfig(link.getConnectorLinkConfig().getConfigs(), diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java index c385434b..6854500d 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java +++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java @@ -39,8 +39,8 @@ public class Constants { public static final String OPT_TO = "to"; public static final String OPT_ALL = "all"; public static final String OPT_JID = "jid"; - public static final String OPT_CID = "cid"; public static final String OPT_NAME = "name"; + public static final String OPT_CONNECTOR_NAME = "connector"; public static final String OPT_VALUE = "value"; public static final String OPT_VERBOSE = "verbose"; public static final String OPT_HOST = "host"; @@ -66,8 +66,8 @@ public class Constants { public static final char OPT_TO_CHAR = 't'; public static final char OPT_ALL_CHAR = 'a'; public static final char OPT_JID_CHAR = 'j'; - public static final char OPT_CID_CHAR = 'c'; public static final char OPT_NAME_CHAR = 'n'; + public static final char OPT_CONNECTOR_NAME_CHAR = 'c'; public static final char OPT_VALUE_CHAR = 'v'; public static final char OPT_HOST_CHAR = 'h'; public static final char OPT_PORT_CHAR = 'p'; @@ -157,8 +157,6 @@ public class Constants { "args.to_missing"; public static final String RES_ARGS_JID_MISSING = "args.jid_missing"; - public static final String RES_ARGS_CID_MISSING = - "args.cid_missing"; public static final String RES_ARGS_NAME_MISSING = "args.name_missing"; public static final String RES_ARGS_VALUE_MISSING = @@ -168,8 +166,8 @@ public class Constants { "prompt.link_id"; public static final String RES_PROMPT_JOB_ID = "prompt.job_id"; - public static final String RES_CONNECTOR_ID = - "prompt.connector_id"; + public static final String RES_CONNECTOR_NAME = + "prompt.connector_name"; public static final String RES_PROMPT_UPDATE_LINK_CONFIG = "prompt.update_link_config"; public static final String RES_PROMPT_UPDATE_JOB_CONFIG = @@ -265,8 +263,8 @@ public class Constants { "show.prompt_links_to_show"; public static final String RES_SHOW_PROMPT_LINK_INFO = "show.prompt_link_info"; - public static final String RES_SHOW_PROMPT_LINK_CID_INFO = - "show.prompt_link_cid_info"; + public static final String RES_SHOW_PROMPT_LINK_CN_INFO = + "show.prompt_link_cn_info"; public static final String RES_SHOW_ROLE_BAD_ARGUMENTS_PRINCIPAL_TYPE = "show.role.bad_arguments_principal_type"; public static final String RES_SHOW_PRIVILEGE_BAD_ARGUMENTS_RESOURCE_TYPE = @@ -274,8 +272,8 @@ public class Constants { public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS = "show.prompt_display_all_connectors"; - public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID = - "show.prompt_display_connector_cid"; + public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_NAME = + "show.prompt_display_connector_name"; public static final String RES_SHOW_PROMPT_CONNECTORS_TO_SHOW = "show.prompt_connectors_to_show"; public static final String RES_SHOW_PROMPT_CONNECTOR_INFO = @@ -288,8 +286,8 @@ public class Constants { public static final String RES_SHOW_PROMPT_DISPLAY_ALL_JOBS = "show.prompt_display_all_jobs"; - public static final String RES_SHOW_PROMPT_DISPLAY_JOBS_CID = - "show.prompt_display_all_jobs_cid"; + public static final String RES_SHOW_PROMPT_DISPLAY_JOBS_CN = + "show.prompt_display_all_jobs_cn"; public static final String RES_SHOW_PROMPT_DISPLAY_JOB_JID = "show.prompt_display_job_jid"; public static final String RES_SHOW_PROMPT_JOBS_TO_SHOW = @@ -369,8 +367,6 @@ public class Constants { "table.header.supported_directions"; public static final String RES_TABLE_HEADER_CONNECTOR_NAME = "table.header.connector.name"; - public static final String RES_TABLE_HEADER_CONNECTOR_ID = - "table.header.connector.id"; public static final String RES_TABLE_HEADER_FROM_CONNECTOR = "table.header.connector.from"; public static final String RES_TABLE_HEADER_TO_CONNECTOR = diff --git a/shell/src/main/resources/shell-resource.properties b/shell/src/main/resources/shell-resource.properties index 50c32b6a..cfd07adc 100644 --- a/shell/src/main/resources/shell-resource.properties +++ b/shell/src/main/resources/shell-resource.properties @@ -42,7 +42,7 @@ args.value_missing = Required argument --value is missing. ## Generic description of various ids, types etc prompt.link_id = Link Id -prompt.connector_id = Connector Id +prompt.connector_name = Connector Name prompt.job_id = Job Id prompt.job_type = Job type @@ -78,7 +78,7 @@ create.link_successful = New link was successfully created with \ create.job_successful = New job was successfully created with validation \ status {0} and persistent id {1} create.role_successful = New role was successfully created with name {0} -create.creating_link = Creating link for connector with id {0} +create.creating_link = Creating link for connector with name {0} create.creating_job = Creating job for links with from id {0} and to id {1} # Delete command @@ -133,13 +133,13 @@ show.prompt_display_link_lid = Display the link with lid show.link_usage = Usage: show link show.prompt_links_to_show = @|bold {0} link(s) to show: |@ show.prompt_link_info = link with id {0} and name {1} (Enabled: {2}, Created by {3} at {4}, Updated by {5} at {6}) -show.prompt_link_cid_info = Using Connector @|bold {0}|@ with id @|bold {1}|@ +show.prompt_link_cn_info = Using Connector @|bold {0}|@ with name @|bold {1}|@ show.prompt_display_all_connectors = Display all connectors -show.prompt_display_connector_cid = Display the connector with cid +show.prompt_display_connector_name = Display the connector with name show.connector_usage = Usage: show connector show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@ -show.prompt_connector_info = Connector with id {0}:\n Name: {1} \n \ +show.prompt_connector_info = Connector with Name: {0} \n \ Class: {2}\n Version: {3}\n Supported Directions {4} show.role.bad_arguments_principal_type = @|bold principal |@ and @|bold principal-type |@ must be used together. show.privilege.bad_arguments_resource_type = @|bold resource |@ and @|bold resource-type |@ must be used together. @@ -148,7 +148,7 @@ show.driver_usage = Usage: show driver show.prompt_driver_opts = @|bold Driver specific options: |@\nPersistent id: {0} show.prompt_display_all_jobs = Display all jobs -show.prompt_display_all_jobs_cid = Display all jobs with given cid +show.prompt_display_all_jobs_cn = Display all jobs with given connector name show.prompt_display_job_jid = Display job with given jid show.job_usage = Usage: show job show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@ @@ -213,7 +213,6 @@ table.header.name = Name table.header.version = Version table.header.class = Class table.header.supported_directions = Supported Directions -table.header.connector.id = Connector Id table.header.connector.name = Connector Name table.header.connector.from = From Connector table.header.connector.to = To Connector diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java index 11c670b6..1f559b61 100644 --- a/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java +++ b/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java @@ -112,34 +112,20 @@ public void testCreateLink() { Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test")); assertTrue(status != null && status == Status.OK); - // create link -cid connector_test - status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-cid", "connector_test")); + // create link -connector connector_test + status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-connector", "connector_test")); assertTrue(status != null && status == Status.OK); // incorrect command: create link -c try { status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c")); - fail("Create link should fail as connector id/name is missing!"); + fail("Create link should fail as connector name is missing!"); } catch (SqoopException e) { assertEquals(ShellError.SHELL_0003, e.getErrorCode()); assertTrue(e.getMessage().contains("Missing argument for option")); } } - @Test - public void testCreateLinkWithNonExistingConnector() { - ShellEnvironment.setInteractive(false); - when(client.getConnector(any(String.class))).thenThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "Connector doesn't exist")); - when(client.getConnector(any(Integer.class))).thenThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "Connector doesn't exist")); - - try { - createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test")); - fail("Create link should fail as requested connector doesn't exist!"); - } catch (SqoopException e) { - assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode()); - } - } - @Test public void testCreateLinkInteractive() { ShellEnvironment.setInteractive(true); diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java index 37c7cf6f..cced4765 100644 --- a/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java +++ b/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java @@ -154,7 +154,7 @@ public void testShowVersion() { public void testShowConnector() { when(client.getConnectors()).thenReturn(new ArrayList()); when(client.getConnector(any(String.class))).thenReturn( - new MConnector("", "", "", + new MConnector("test_connector", "", "", new MLinkConfig(new ArrayList(), new ArrayList()), new MFromConfig(new ArrayList(), new ArrayList()), new MToConfig(new ArrayList(), new ArrayList()))); @@ -164,7 +164,6 @@ public void testShowConnector() { Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR)); Assert.assertTrue(status != null && status == Status.OK); String str = new String(out.toByteArray()); - Assert.assertTrue(str.contains("Id")); Assert.assertTrue(str.contains("Name")); Assert.assertTrue(str.contains("Version")); Assert.assertTrue(str.contains("Class")); @@ -177,12 +176,12 @@ public void testShowConnector() { str = new String(out.toByteArray()); Assert.assertTrue(str.contains("connector(s) to show:")); - // show connector -cid 1 + // show connector -name test_connector out.reset(); - status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-cid", "1")); + status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-name", "test_connector")); Assert.assertTrue(status != null && status == Status.OK); str = new String(out.toByteArray()); - Assert.assertTrue(str.contains("Connector with id")); + Assert.assertTrue(str.contains("Connector with Name: test_connector")); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -212,7 +211,6 @@ public void testShowLink() { String str = new String(out.toByteArray()); Assert.assertTrue(str.contains("Id")); Assert.assertTrue(str.contains("Name")); - Assert.assertTrue(str.contains("Connector Id")); Assert.assertTrue(str.contains("Connector Name")); Assert.assertTrue(str.contains("Enabled")); @@ -239,7 +237,7 @@ public void testShowJob() { new MFromConfig(new ArrayList(), new ArrayList()), new MToConfig(new ArrayList(), new ArrayList()), new MDriverConfig(new ArrayList(), new ArrayList()))); - when(client.getJobsByConnector("2")).thenReturn(Arrays.asList(new MJob("fromConnectorName", "toConnectorName", + when(client.getJobsByConnector("fromConnectorName")).thenReturn(Arrays.asList(new MJob("fromConnectorName", "toConnectorName", "linkName1", "linkName2", new MFromConfig(new ArrayList(), new ArrayList()), new MToConfig(new ArrayList(), new ArrayList()), new MDriverConfig(new ArrayList(), new ArrayList())))); @@ -269,9 +267,9 @@ public void testShowJob() { str = new String(out.toByteArray()); Assert.assertTrue(str.contains("Job with id")); - // show job -cid 2 + // show job -connector fromConnectorName out.reset(); - status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-cid", "2")); + status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-connector", "fromConnectorName")); Assert.assertTrue(status != null && status == Status.OK); str = new String(out.toByteArray()); Assert.assertTrue(str.contains("job(s) to show:"));