sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject [2/2] sqoop git commit: SQOOP-2630: Sqoop2: Provide tests for all SqoopCommand
Date Thu, 22 Oct 2015 14:47:09 GMT
SQOOP-2630: Sqoop2: Provide tests for all SqoopCommand

(Dian Fu via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/21526151
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/21526151
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/21526151

Branch: refs/heads/sqoop2
Commit: 21526151f5808747b6ab0eedc4c445308e188d07
Parents: 6a10db0
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Thu Oct 22 07:46:45 2015 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Thu Oct 22 07:46:45 2015 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/client/SqoopClient.java    |   9 +-
 .../client/request/SqoopResourceRequests.java   |  17 +
 .../apache/sqoop/shell/ShellEnvironment.java    |   7 +
 .../apache/sqoop/shell/ShowOptionFunction.java  |   1 -
 .../sqoop/shell/ShowPrincipalFunction.java      |   6 +-
 .../apache/sqoop/shell/ShowVersionFunction.java |  21 +-
 .../apache/sqoop/shell/TestCloneCommand.java    | 127 ++++++
 .../apache/sqoop/shell/TestCreateCommand.java   |  18 +-
 .../apache/sqoop/shell/TestDeleteCommand.java   | 142 ++++++
 .../apache/sqoop/shell/TestDisableCommand.java  | 111 +++++
 .../apache/sqoop/shell/TestEnableCommand.java   | 111 +++++
 .../apache/sqoop/shell/TestGrantCommand.java    | 202 +++++++++
 .../apache/sqoop/shell/TestRevokeCommand.java   | 218 +++++++++
 .../org/apache/sqoop/shell/TestSetCommand.java  | 151 +++++++
 .../org/apache/sqoop/shell/TestShowCommand.java | 438 +++++++++++++++++++
 .../apache/sqoop/shell/TestStartCommand.java    |  80 ++++
 .../apache/sqoop/shell/TestStatusCommand.java   |  70 +++
 .../org/apache/sqoop/shell/TestStopCommand.java |  70 +++
 .../apache/sqoop/shell/TestUpdateCommand.java   | 127 ++++++
 19 files changed, 1897 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
index 60e0d00..3d3425d 100644
--- a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
+++ b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
@@ -29,7 +29,6 @@ import org.apache.hadoop.security.token.Token;
 import org.apache.sqoop.classification.InterfaceAudience;
 import org.apache.sqoop.classification.InterfaceStability;
 import org.apache.sqoop.client.request.SqoopResourceRequests;
-import org.apache.sqoop.common.Direction;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.json.*;
 import org.apache.sqoop.model.*;
@@ -105,6 +104,10 @@ public class SqoopClient {
     clearCache();
   }
 
+  public String getServerUrl() {
+    return resourceRequests.getServerUrl();
+  }
+
   /**
    * Set arbitrary request object.
    *
@@ -807,6 +810,10 @@ public class SqoopClient {
     return resourceRequests.addDelegationTokens(renewer, credentials);
   }
 
+  public VersionBean readVersion() {
+    return resourceRequests.readVersion();
+  }
+
   private Status applyLinkValidations(ValidationResultBean bean, MLink link) {
     ConfigValidationResult linkConfig = bean.getValidationResults()[0];
     // Apply validation results

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java b/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
index 1803b70..0987703 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
@@ -39,6 +39,7 @@ public class SqoopResourceRequests {
   private JobResourceRequest jobRequest;
   private SubmissionResourceRequest submissionRequest;
   private AuthorizationResourceRequest authorizationRequest;
+  private VersionResourceRequest versionRequest;
   private DelegationTokenAuthenticatedURL.Token authToken;
 
   public SqoopResourceRequests() {
@@ -49,6 +50,10 @@ public class SqoopResourceRequests {
     this.serverUrl = serverUrl;
   }
 
+  public String getServerUrl() {
+    return serverUrl;
+  }
+
   public DriverResourceRequest getDriverResourceRequest() {
     if (driverRequest == null) {
       driverRequest = new DriverResourceRequest(authToken);
@@ -97,6 +102,14 @@ public class SqoopResourceRequests {
     return authorizationRequest;
   }
 
+  public VersionResourceRequest getVersionRequest() {
+    if (versionRequest == null) {
+      versionRequest = new VersionResourceRequest(authToken);
+    }
+
+    return versionRequest;
+  }
+
   public DriverBean readDriver() {
     return getDriverResourceRequest().read(serverUrl);
   }
@@ -205,6 +218,10 @@ public class SqoopResourceRequests {
     getAuthorizationRequest().grantRevokePrivilege(serverUrl, principals, privileges, false);
   }
 
+  public VersionBean readVersion() {
+    return getVersionRequest().read(serverUrl);
+  }
+
   public Token<?>[] addDelegationTokens(String renewer,
                                         Credentials credentials) throws IOException {
     return getDriverResourceRequest().addDelegationTokens(serverUrl + DriverResourceRequest.RESOURCE, renewer, credentials);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java b/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
index caf4b53..b08fdcf 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
@@ -208,5 +208,12 @@ public final class ShellEnvironment {
   public static void print(String format, Object... args) {
     io.out.printf(format, args);
   }
+
+  // for tests only
+  public static void cleanup() {
+    serverHost = DEFAULT_SERVER_HOST;
+    serverPort = DEFAULT_SERVER_PORT;
+    serverWebapp = DEFAULT_SERVER_WEBAPP;
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
index 41d3f1a..e440bea 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
@@ -69,7 +69,6 @@ public class ShowOptionFunction extends SqoopFunction {
       }
     } else {
       printAllOptions();
-      return null;
     }
 
     return Status.OK;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/main/java/org/apache/sqoop/shell/ShowPrincipalFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowPrincipalFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowPrincipalFunction.java
index 8935026..a450aaf 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShowPrincipalFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowPrincipalFunction.java
@@ -48,11 +48,7 @@ public class ShowPrincipalFunction extends SqoopFunction {
 
   @Override
   public Object executeFunction(CommandLine line, boolean isInteractive) {
-    MRole role = null;
-
-    if (line.hasOption(Constants.OPT_ROLE)) {
-      role = new MRole(line.getOptionValue(Constants.OPT_ROLE));
-    }
+    MRole role = new MRole(line.getOptionValue(Constants.OPT_ROLE));
 
     showPrincipals(role);
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
index 16452b5..5c75257 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
@@ -21,7 +21,6 @@ import java.util.Arrays;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.request.VersionResourceRequest;
 import org.apache.sqoop.common.VersionInfo;
 import org.apache.sqoop.json.VersionBean;
 import org.apache.sqoop.shell.core.Constants;
@@ -33,7 +32,6 @@ import static org.apache.sqoop.shell.ShellEnvironment.*;
 @edu.umd.cs.findbugs.annotations.SuppressWarnings("SE_BAD_FIELD")
 public class ShowVersionFunction extends SqoopFunction {
   private static final long serialVersionUID = 1L;
-  private VersionResourceRequest versionRequest;
 
   @SuppressWarnings("static-access")
   public ShowVersionFunction() {
@@ -83,15 +81,15 @@ public class ShowVersionFunction extends SqoopFunction {
     return Status.OK;
   }
 
-  private void showVersion(boolean server, boolean client, boolean restApi) {
+  private void showVersion(boolean showServerVersion, boolean showClientVersion, boolean showRestApiVersion) {
 
     // If no option has been given, print out client version as default
-    if (!client && !server && !restApi) {
-      client = true;
+    if (!showClientVersion && !showServerVersion && !showRestApiVersion) {
+      showClientVersion = true;
     }
 
     // Print out client string if needed
-    if (client) {
+    if (showClientVersion) {
       printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
         Constants.OPT_CLIENT,
         // See SQOOP-1623 to understand how the client version is derived.
@@ -103,16 +101,13 @@ public class ShowVersionFunction extends SqoopFunction {
     }
 
     // If only client version was required we do not need to continue
-    if(!server && !restApi) {
+    if(!showServerVersion && !showRestApiVersion) {
       return;
     }
 
-    if (versionRequest == null) {
-      versionRequest = new VersionResourceRequest();
-    }
-    VersionBean versionBean = versionRequest.read(getServerUrl());
+    VersionBean versionBean = client.readVersion();
 
-    if (server) {
+    if (showServerVersion) {
       printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
         Constants.OPT_SERVER,
         versionBean.getBuildVersion(),
@@ -122,7 +117,7 @@ public class ShowVersionFunction extends SqoopFunction {
       );
     }
 
-    if (restApi) {
+    if (showRestApiVersion) {
       printlnResource(Constants.RES_SHOW_PROMPT_API_VERSIONS,
         Arrays.toString(versionBean.getSupportedAPIVersions())
       );

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestCloneCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestCloneCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestCloneCommand.java
new file mode 100644
index 0000000..f7f44a5
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestCloneCommand.java
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConfig;
+import org.apache.sqoop.model.MDriverConfig;
+import org.apache.sqoop.model.MFromConfig;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MLinkConfig;
+import org.apache.sqoop.model.MToConfig;
+import org.apache.sqoop.model.MValidator;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.utils.MapResourceBundle;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestCloneCommand {
+  CloneCommand cloneCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    cloneCmd = new CloneCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  @Test
+  public void testCloneLink() {
+    MLink link = new MLink(1L, new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()));
+    when(client.getLink("link_test")).thenReturn(link);
+    when(client.getConnectorConfigBundle(1L)).thenReturn(new MapResourceBundle(new HashMap()));
+    when(client.saveLink(link)).thenReturn(Status.OK);
+
+    // clone link -lid link_test
+    Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option lid
+    try {
+      cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid"));
+      Assert.fail("Update link should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing option lid
+    try {
+      cloneCmd.execute(Arrays.asList(Constants.FN_LINK));
+      Assert.fail("Update link should fail as option lid is missing");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  @Test
+  public void testCloneJob() {
+    MJob job = new MJob(1L, 2L, 1L, 2L,
+        new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()));
+    when(client.getJob("job_test")).thenReturn(job);
+    when(client.getConnectorConfigBundle(any(Long.class))).thenReturn(new MapResourceBundle(new HashMap()));
+    when(client.getDriverConfigBundle()).thenReturn(new MapResourceBundle(new HashMap()));
+    when(client.saveJob(job)).thenReturn(Status.OK);
+
+    // update job -jid job_test
+    Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option jid
+    try {
+      cloneCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid"));
+      Assert.fail("Update job should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing option jid
+    try {
+      cloneCmd.execute(Arrays.asList(Constants.FN_JOB));
+      Assert.fail("Update job should fail as option jid is missing");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java
----------------------------------------------------------------------
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 80ce55e..e0788cc 100644
--- a/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestCreateCommand.java
@@ -60,16 +60,16 @@ public class TestCreateCommand {
 
   @Test
   public void testCreateLink() {
-    when(client.getConnector("connector_1")).thenReturn(new MConnector("", "", "", null, null, null));
-    when(client.createLink("connector_1")).thenReturn(new MLink(1, new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
+    when(client.getConnector("connector_test")).thenReturn(new MConnector("", "", "", null, null, null));
+    when(client.createLink("connector_test")).thenReturn(new MLink(1, new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
     when(client.saveLink(any(MLink.class))).thenReturn(Status.OK);
 
-    // create link -c connector_1
-    Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_1"));
+    // create link -c connector_test
+    Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test"));
     Assert.assertTrue(status != null && status == Status.OK);
 
-    // create link -cid connector_1
-    status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-cid", "connector_1"));
+    // create link -cid connector_test
+    status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-cid", "connector_test"));
     Assert.assertTrue(status != null && status == Status.OK);
 
     // incorrect command: create link -c
@@ -88,7 +88,7 @@ public class TestCreateCommand {
     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_1"));
+      createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test"));
       Assert.fail("Create link should fail as requested connector doesn't exist!");
     } catch (SqoopException e) {
       Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
@@ -135,8 +135,8 @@ public class TestCreateCommand {
 
   @Test
   public void testCreateRole() {
-    // create role -r role_1
-    Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_ROLE, "-r", "role_1"));
+    // create role -r role_test
+    Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_ROLE, "-r", "role_test"));
     Assert.assertTrue(status != null && status == Status.OK);
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestDeleteCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestDeleteCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestDeleteCommand.java
new file mode 100644
index 0000000..7b65f7e
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestDeleteCommand.java
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+
+import java.util.Arrays;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestDeleteCommand {
+  DeleteCommand deleteCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    deleteCmd = new DeleteCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testDeleteLink() {
+    doNothing().when(client).deleteLink("link_test");
+
+    // delete link -l link_test
+    Status status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option lid
+    try {
+      status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid"));
+      Assert.fail("Delete link should fail as link id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testDeleteLinkWithNonExistingLink() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).deleteLink(any(String.class));
+
+    try {
+      deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test"));
+      Assert.fail("Delete link should fail as requested link doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+
+  @Test
+  public void testDeleteJob() {
+    doNothing().when(client).deleteJob("job_test");
+
+    // delete job -j job_test
+    Status status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_JOB, "-j", "job_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option jid
+    try {
+      status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid"));
+      Assert.fail("Delete job should fail as job id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testDeleteJobWithNonExistingJob() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "job doesn't exist")).when(client).deleteJob(any(String.class));
+
+    try {
+      deleteCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test"));
+      Assert.fail("Delete job should fail as requested job doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+
+  @Test
+  public void testDeleteRole() {
+    doNothing().when(client).dropRole(any(MRole.class));
+
+    // delete role -r role_test
+    Status status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_ROLE, "-r", "role_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option role
+    try {
+      status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role"));
+      Assert.fail("Delete role should fail as role name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testDeleteRoleWithNonExistingRole() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "role doesn't exist")).when(client).dropRole(any(MRole.class));
+
+    try {
+      deleteCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role", "role_test"));
+      Assert.fail("Delete role should fail as requested role doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestDisableCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestDisableCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestDisableCommand.java
new file mode 100644
index 0000000..282f512
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestDisableCommand.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+
+import java.util.Arrays;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestDisableCommand {
+  DisableCommand disableCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    disableCmd = new DisableCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testDisableLink() {
+    doNothing().when(client).enableLink("link_test", false);
+
+    // disable link -l link_test
+    Status status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option lid
+    try {
+      status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid"));
+      Assert.fail("Disable link should fail as link id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testDisableLinkWithNonExistingLink() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class));
+
+    try {
+      disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test"));
+      Assert.fail("Disable link should fail as requested link doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+
+  @Test
+  public void testDisableJob() {
+    doNothing().when(client).enableJob("job_test", false);
+
+    // disable job -j job_test
+    Status status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_JOB, "-j", "job_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option jid
+    try {
+      status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid"));
+      Assert.fail("Disable job should fail as job id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testDisableJobWithNonExistingJob() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "job doesn't exist")).when(client).enableJob(any(String.class), any(Boolean.class));
+
+    try {
+      disableCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test"));
+      Assert.fail("Disable job should fail as requested job doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestEnableCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestEnableCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestEnableCommand.java
new file mode 100644
index 0000000..d286251
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestEnableCommand.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+
+import java.util.Arrays;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestEnableCommand {
+  EnableCommand enableCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    enableCmd = new EnableCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testEnableLink() {
+    doNothing().when(client).enableLink("link_test", true);
+
+    // enable link -l link_test
+    Status status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option lid
+    try {
+      status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid"));
+      Assert.fail("Enable link should fail as link id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testEnableLinkWithNonExistingLink() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class));
+
+    try {
+      enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test"));
+      Assert.fail("Enable link should fail as requested link doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+
+  @Test
+  public void testEnableJob() {
+    doNothing().when(client).enableJob("job_test", true);
+
+    // enable job -j job_test
+    Status status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_JOB, "-j", "job_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for option jid
+    try {
+      status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid"));
+      Assert.fail("Enable job should fail as job id/name is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testEnableJobWithNonExistingJob() {
+    doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "job doesn't exist")).when(client).enableJob(any(String.class), any(Boolean.class));
+
+    try {
+      enableCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test"));
+      Assert.fail("Enable job should fail as requested job doesn't exist!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestGrantCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestGrantCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestGrantCommand.java
new file mode 100644
index 0000000..9f7f5b8
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestGrantCommand.java
@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doNothing;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestGrantCommand {
+  GrantCommand grantCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    grantCmd = new GrantCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testGrantRole() {
+    doNothing().when(client).grantRole(any(List.class), any(List.class));
+
+    // grant role -principal_type user -principal principal_test -role role_test
+    Status status = (Status) grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "user", "-principal", "principal_test", "-role", "role_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // principal_type is not correct
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "non_existing_principal_type", "-principal", "principal_test", "-role", "role_test"));
+      Assert.fail("Grant role should fail as principal-type is not among user/group/role!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // Missing argument for principal_type
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type"));
+      Assert.fail("Grant role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing argument for principal
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal"));
+      Assert.fail("Grant role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing argument for role name
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role"));
+      Assert.fail("Grant role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing options principal-type and principal
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role", "role_test"));
+      Assert.fail("Grant role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing options principal-type and role name
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal", "principal_test"));
+      Assert.fail("Grant role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing options principal and role name
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "role"));
+      Assert.fail("Grant role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option principal-type
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role", "role_test", "-principal", "principal_test"));
+      Assert.fail("Grant role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option role
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "group", "-principal", "principal_test"));
+      Assert.fail("Grant role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testGrantPrivilege() {
+    doNothing().when(client).grantPrivilege(any(List.class), any(List.class));
+
+    // grant privilege -resource-type connector -resource resource_test -action read -principal principal_test -principal_type group -with-grant
+    Status status = (Status) grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // resource-type is not correct
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "non_existing_resource_type", "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Grant privilege should fail as resource-type is not among server/connector/link/job!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // action is not correct
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "non_existing_action", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Grant privilege should fail as action is not among read/write/all!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // principal-type is not correct
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-principal-type", "non_existing_principal_type", "-with-grant"));
+      Assert.fail("Grant privilege should fail as principal-type is not among user/group/role!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // Missing argument for option resource-type
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-principal-type", "non_existing_principal_type", "-with-grant"));
+      Assert.fail("Grant privilege should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing option principal-type
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-with-grant"));
+      Assert.fail("Grant privilege should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option action
+    try {
+      grantCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Grant privilege should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestRevokeCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestRevokeCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestRevokeCommand.java
new file mode 100644
index 0000000..88f04f2
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestRevokeCommand.java
@@ -0,0 +1,218 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doNothing;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestRevokeCommand {
+  RevokeCommand revokeCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    revokeCmd = new RevokeCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testRevokeRole() {
+    doNothing().when(client).revokeRole(any(List.class), any(List.class));
+
+    // revoke role -principal_type user -principal principal_test -role role_1
+    Status status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "user", "-principal", "principal_test", "-role", "role_1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // principal_type is not correct
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "non_existing_principal_type", "-principal", "principal_test", "-role", "role_1"));
+      Assert.fail("Revoke role should fail as principal-type is not among user/group/role!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // Missing argument for principal_type
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type"));
+      Assert.fail("Revoke role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing argument for principal
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal"));
+      Assert.fail("Revoke role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing argument for role name
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role"));
+      Assert.fail("Revoke role should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Missing options principal-type and principal
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role", "role_1"));
+      Assert.fail("Revoke role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing options principal-type and role name
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal", "principal_test"));
+      Assert.fail("Revoke role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing options principal and role name
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "role"));
+      Assert.fail("Revoke role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option principal-type
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-role", "role_1", "-principal", "principal_test"));
+      Assert.fail("Revoke role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option role
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "group", "-principal", "principal_test"));
+      Assert.fail("Revoke role should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testRevokePrivilege() {
+    doNothing().when(client).revokePrivilege(any(List.class), any(List.class));
+
+    // revoke privilege -resource-type connector -resource resource_test -action read -principal principal_test -principal_type group -with-grant
+    Status status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // resource-type is not correct
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "non_existing_resource_type", "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as resource-type is not among server/connector/link/job!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // action is not correct
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "non_existing_action", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as action is not among read/write/all!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // principal-type is not correct
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-principal-type", "non_existing_principal_type", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as principal-type is not among user/group/role!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("No enum constant"));
+    }
+
+    // Missing argument for option resource-type
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-principal-type", "non_existing_principal_type", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+
+    // Revoke all privileges for principal: revoke privilege -principal principal_test -principal_type group -with-grant
+    status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing option principal-type
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "write", "-principal", "principal_test", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option principal
+    try {
+      revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-action", "write", "-principal-type", "group", "-with-grant"));
+      Assert.fail("Revoke privilege should fail as of missing required options!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // option resource, resource-type and action must be used together: missing option action
+    status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-resource", "resource_test", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.ERROR);
+
+    // option resource, resource-type and action must be used together: missing option resource
+    status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource-type", "connector", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.ERROR);
+
+    // option resource, resource-type and action must be used together: missing option resource-type
+    status = (Status) revokeCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-resource", "resource_test", "-action", "read", "-principal", "principal_test", "-principal-type", "group", "-with-grant"));
+    Assert.assertTrue(status != null && status == Status.ERROR);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestSetCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestSetCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestSetCommand.java
new file mode 100644
index 0000000..b231cf2
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestSetCommand.java
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import java.util.Arrays;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestSetCommand {
+  SetCommand setCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    setCmd = new SetCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = new SqoopClient(StringUtils.EMPTY);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testSetServer() {
+    ShellEnvironment.cleanup();
+    // set server -url http://host-test:7070/sqoop-test
+    Status status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+    // use the default webapp path if not specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertTrue(client.getServerUrl().equals("http://host-test:7070/sqoop/"));
+
+    // use the default webapp and port if not specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test/"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertTrue(client.getServerUrl().equals("http://host-test:12000/sqoop/"));
+
+    // option host is ignored when option url is specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-host", "host2-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+    // option port is ignored when option url is specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-port", "12000"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+    // option webapp is ignored when option url is specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-webapp", "sqoop2-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+    // Missing argument for option url
+    try {
+      status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-url"));
+      Assert.fail("Set server should fail as url is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testSetServerWithoutOptionURL() {
+    ShellEnvironment.cleanup();
+    // use option host, port, webapp when option url is not specified
+    Status status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-port", "7070", "-webapp", "sqoop2-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host2-test:7070/sqoop2-test/");
+
+    ShellEnvironment.cleanup();
+    // use default host if option host is not specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-port", "7070", "-webapp", "sqoop2-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://localhost:7070/sqoop2-test/");
+
+    ShellEnvironment.cleanup();
+    // use default port if option port is not specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-webapp", "sqoop2-test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host2-test:12000/sqoop2-test/");
+
+    ShellEnvironment.cleanup();
+    // use default webapp if option webapp is not specified
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-port", "7070"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(client.getServerUrl(), "http://host2-test:7070/sqoop/");
+  }
+
+  @Test
+  public void testSetOption() {
+    // set option -name verbose -value true
+    Status status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "true"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertTrue(ShellEnvironment.isVerbose());
+
+    // set option -name verbose -value 1
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertTrue(ShellEnvironment.isVerbose());
+
+    // set option -name verbose -value 0
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "0"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertFalse(ShellEnvironment.isVerbose());
+
+    // set option -name poll-timeout -value 12345
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "poll-timeout", "-value", "12345"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+
+    // when value of poll-timeout is not number, poll-timeout should stay the old value
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "poll-timeout", "-value", "abc"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+
+    // skip non exist options, options already set should stay the old value
+    status = (Status) setCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "non-exist-option", "-value", "opt-value"));
+    Assert.assertTrue(status == null);
+    Assert.assertFalse(ShellEnvironment.isVerbose());
+    Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java
new file mode 100644
index 0000000..4272386
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestShowCommand.java
@@ -0,0 +1,438 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.json.VersionBean;
+import org.apache.sqoop.model.MConfig;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MDriver;
+import org.apache.sqoop.model.MDriverConfig;
+import org.apache.sqoop.model.MFromConfig;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MLinkConfig;
+import org.apache.sqoop.model.MPrincipal;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.model.MToConfig;
+import org.apache.sqoop.model.MValidator;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.utils.MapResourceBundle;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.codehaus.groovy.tools.shell.IO;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestShowCommand {
+  ShowCommand showCmd;
+  SqoopClient client;
+  ByteArrayOutputStream out;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    showCmd = new ShowCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    out = new ByteArrayOutputStream();
+    ShellEnvironment.setIo(new IO(System.in, out, System.err));
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testShowServer() throws IOException {
+    // show server -host -port -webapp
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SERVER, "-host", "-port", "-webapp"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Server host:"));
+    Assert.assertTrue(str.contains("Server port:"));
+    Assert.assertTrue(str.contains("Server webapp:"));
+
+    // show server -all
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SERVER, "-all"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Server host:"));
+    Assert.assertTrue(str.contains("Server port:"));
+    Assert.assertTrue(str.contains("Server webapp:"));
+
+    // show server -host
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SERVER, "-host"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Server host:"));
+    Assert.assertFalse(str.contains("Server port:"));
+    Assert.assertFalse(str.contains("Server webapp:"));
+
+    // show server -port
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SERVER, "-port"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertFalse(str.contains("Server host:"));
+    Assert.assertTrue(str.contains("Server port:"));
+    Assert.assertFalse(str.contains("Server webapp:"));
+
+    // show server -webapp
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SERVER, "-webapp"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertFalse(str.contains("Server host:"));
+    Assert.assertFalse(str.contains("Server port:"));
+    Assert.assertTrue(str.contains("Server webapp:"));
+  }
+
+  @Test
+  public void testShowVersion() {
+    when(client.readVersion()).thenReturn(new VersionBean());
+
+    // show version -server -client -api
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_VERSION, "-server", "-client", "-api"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("server version:"));
+    Assert.assertTrue(str.contains("client version:"));
+    Assert.assertTrue(str.contains("API versions:"));
+
+    // show version -all
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_VERSION, "-all"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("server version:"));
+    Assert.assertTrue(str.contains("client version:"));
+    Assert.assertTrue(str.contains("API versions:"));
+
+    // show client version when no option is specified
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_VERSION));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertFalse(str.contains("server version:"));
+    Assert.assertTrue(str.contains("client version:"));
+    Assert.assertFalse(str.contains("API versions:"));
+  }
+
+  @Test
+  public void testShowConnector() {
+    when(client.getConnectors()).thenReturn(new ArrayList<MConnector>());
+    when(client.getConnector(any(String.class))).thenReturn(
+        new MConnector("", "", "",
+            new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+            new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+            new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
+
+    // show connector summary
+    out.reset();
+    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"));
+    Assert.assertTrue(str.contains("Supported Directions"));
+
+    // show connector -all
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-all"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("connector(s) to show:"));
+
+    // show connector -cid 1
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-cid", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Connector with id"));
+  }
+
+  @SuppressWarnings({ "rawtypes", "unchecked" })
+  @Test
+  public void testShowDriver() {
+    when(client.getDriver()).thenReturn(new MDriver(new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), ""));
+    when(client.getDriverConfig()).thenReturn(new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()));
+    when(client.getDriverConfigBundle()).thenReturn(new MapResourceBundle(new HashMap()));
+
+    // show driver
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_DRIVER_CONFIG));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Driver specific options:"));
+  }
+
+  @Test
+  public void testShowLink() {
+    when(client.getLinks()).thenReturn(new ArrayList<MLink>());
+    when(client.getLink(any(String.class))).thenReturn(new MLink(1L, new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
+
+    // show link summary
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK));
+    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("Connector Id"));
+    Assert.assertTrue(str.contains("Connector Name"));
+    Assert.assertTrue(str.contains("Enabled"));
+
+    // show link -all
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK, "-all"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("link(s) to show:"));
+
+    // show link -lid 1
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("link with id"));
+  }
+
+  @Test
+  public void testShowJob() {
+    when(client.getJobs()).thenReturn(new ArrayList<MJob>());
+    when(client.getJob("1")).thenReturn(new MJob(1L, 2L, 1L, 2L,
+        new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
+    when(client.getJobsByConnector("2")).thenReturn(Arrays.asList(new MJob(1L, 2L, 1L, 2L,
+        new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
+        new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()))));
+
+    // show job summary
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB));
+    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("From Connector"));
+    Assert.assertTrue(str.contains("To Connector"));
+    Assert.assertTrue(str.contains("Enabled"));
+
+    // show job -all
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-all"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("job(s) to show:"));
+
+    // show job -jid 1
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Job with id"));
+
+    // show job -cid 2
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-cid", "2"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("job(s) to show:"));
+  }
+
+  @Test
+  public void testShowSubmission() {
+    when(client.getSubmissions()).thenReturn(Arrays.asList(new MSubmission(1L)));
+    when(client.getSubmissionsForJob(any(String.class))).thenReturn(Arrays.asList(new MSubmission(1L)));
+
+    // show submission -details -jid 1
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SUBMISSION, "-detail", "-jid", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Submission details"));
+
+    // show submission -details
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SUBMISSION, "-detail"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Submission details"));
+
+    // show submission -jid 1
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SUBMISSION, "-jid", "1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Job Id"));
+    Assert.assertTrue(str.contains("External Id"));
+    Assert.assertTrue(str.contains("Status"));
+    Assert.assertTrue(str.contains("Last Update Date"));
+
+    // show submission
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_SUBMISSION));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Job Id"));
+    Assert.assertTrue(str.contains("External Id"));
+    Assert.assertTrue(str.contains("Status"));
+    Assert.assertTrue(str.contains("Last Update Date"));
+  }
+
+  @Test
+  public void testShowOption() {
+    // show option -name verbose
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Verbose ="));
+
+    // show option -name poll-timeout
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_OPTION, "-name", "poll-timeout"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Poll-timeout ="));
+
+    // show all options
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_OPTION));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Verbose ="));
+    Assert.assertTrue(str.contains("Poll-timeout ="));
+  }
+
+  @Test
+  public void testShowRole() {
+    when(client.getRolesByPrincipal(any(MPrincipal.class))).thenReturn(new ArrayList<MRole>());
+    // show role -principal-type user -principal principal_1
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_ROLE, "-principal-type", "user", "-principal", "principal_1"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Role Name"));
+
+    when(client.getRoles()).thenReturn(new ArrayList<MRole>());
+    // show role
+    out.reset();
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_ROLE));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Role Name"));
+  }
+
+  @Test
+  public void testShowPrincipal() {
+    when(client.getPrincipalsByRole(any(MRole.class))).thenReturn(new ArrayList<MPrincipal>());
+    // show principal -role role_test
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_PRINCIPAL, "-role", "role_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Principal Name"));
+    Assert.assertTrue(str.contains("Principal Type"));
+
+    // Missing option role name
+    try {
+      showCmd.execute(Arrays.asList(Constants.FN_PRINCIPAL));
+      Assert.fail("Show principal should fail as role name is missing!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+
+  @Test
+  public void testShowPrivilege() {
+    when(client.getPrincipalsByRole(any(MRole.class))).thenReturn(new ArrayList<MPrincipal>());
+    // show privilege -principal-type user -principal principal_test -resource-type connector -resource resource_test
+    out.reset();
+    Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE,
+        "-principal-type", "user", "-principal", "principal_test", "-resource-type", "connector", "-resource", "resource_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    String str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Action"));
+    Assert.assertTrue(str.contains("Resource Name"));
+    Assert.assertTrue(str.contains("Resource Type"));
+    Assert.assertTrue(str.contains("With Grant"));
+
+    // show privilege -principal-type user -principal principal_test
+    status = (Status) showCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-principal-type", "user", "-principal", "principal_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+    str = new String(out.toByteArray());
+    Assert.assertTrue(str.contains("Action"));
+    Assert.assertTrue(str.contains("Resource Name"));
+    Assert.assertTrue(str.contains("Resource Type"));
+    Assert.assertTrue(str.contains("With Grant"));
+
+    // options resource-type and resource must be used together: missing option resource
+    try {
+      showCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-principal-type", "user", "-principal", "principal_test", "-resource-type", "connector"));
+      Assert.fail("Show principal should fail as option resource is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(e.getErrorCode(), ShellError.SHELL_0003);
+    }
+
+    // options resource-type and resource must be used together: missing option resource-type
+    try {
+      showCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-principal-type", "user", "-principal", "principal_test", "-resource", "resource_test"));
+      Assert.fail("Show principal should fail as option resource-type is missing!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(e.getErrorCode(), ShellError.SHELL_0003);
+    }
+
+    // Missing option principal-type
+    try {
+      showCmd.execute(Arrays.asList(Constants.FN_PRIVILEGE, "-principal", "principal_test", "-resource-type", "connector", "-resource", "resource_test"));
+      Assert.fail("Show privilege should fail as option principal-type is missing!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+
+    // Missing option principal
+    try {
+      showCmd.execute(Arrays.asList(Constants.FN_PRINCIPAL, "-principal-type", "group", "-resource-type", "connector", "-resource", "resource_test"));
+      Assert.fail("Show privilege should fail as option principal is missing!");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().contains("Missing required option"));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/21526151/shell/src/test/java/org/apache/sqoop/shell/TestStartCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestStartCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestStartCommand.java
new file mode 100644
index 0000000..17ce291
--- /dev/null
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestStartCommand.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop.shell;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.client.SubmissionCallback;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestStartCommand {
+  StartCommand startCmd;
+  SqoopClient client;
+
+  @BeforeTest(alwaysRun = true)
+  public void setup() {
+    Groovysh shell = new Groovysh();
+    startCmd = new StartCommand(shell);
+    ShellEnvironment.setInteractive(false);
+    ShellEnvironment.setIo(shell.getIo());
+    client = mock(SqoopClient.class);
+    ShellEnvironment.setClient(client);
+  }
+
+  @Test
+  public void testStartJobSynchronousDisabled() throws InterruptedException {
+    MSubmission submission = new MSubmission();
+    when(client.startJob(any(String.class))).thenReturn(submission);
+
+    // start job -jid job_test
+    Status status = (Status) startCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test"));
+    Assert.assertTrue(status != null && status == Status.OK);
+
+    // Missing argument for jid
+    try {
+      startCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid"));
+      Assert.fail("Start job should fail as parameters aren't complete!");
+    } catch (SqoopException e) {
+      Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testStartJobSynchronousEnabled() throws InterruptedException {
+    when(client.startJob(any(String.class), any(SubmissionCallback.class), any(Long.class))).thenReturn(null);
+
+    // start job -jid job_test -synchronous
+    Status status = (Status) startCmd.execute(Arrays.asList(Constants.FN_JOB, "-jid", "job_test", "-synchronous"));
+    Assert.assertTrue(status != null && status == Status.OK);
+  }
+}


Mime
View raw message