sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject [1/2] sqoop git commit: SQOOP-2763: Sqoop2: Sqoop shell is accepting non existing arguments
Date Tue, 05 Jan 2016 14:32:42 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 073da06dd -> c40c23c9e


http://git-wip-us.apache.org/repos/asf/sqoop/blob/c40c23c9/shell/src/test/java/org/apache/sqoop/shell/TestStopCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestStopCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestStopCommand.java
index e2bc6b8..ca9d03b 100644
--- a/shell/src/test/java/org/apache/sqoop/shell/TestStopCommand.java
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestStopCommand.java
@@ -21,6 +21,9 @@ package org.apache.sqoop.shell;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
 import java.util.Arrays;
 
@@ -31,7 +34,6 @@ 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;
 
@@ -56,15 +58,25 @@ public class TestStopCommand {
 
     // stop job -name job_test
     Status status = (Status) stopCmd.execute(Arrays.asList(Constants.FN_JOB, "-name", "job_test"));
-    Assert.assertTrue(status != null && status == Status.OK);
+    assertTrue(status != null && status == Status.OK);
 
     // Missing argument for name
     try {
       stopCmd.execute(Arrays.asList(Constants.FN_JOB, "-name"));
-      Assert.fail("Stop job should fail as parameters aren't complete!");
+      fail("Stop 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"));
+      assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+      assertTrue(e.getMessage().contains("Missing argument for option"));
+    }
+  }
+
+  @Test
+  public void testUnknowOption() {
+    try {
+      stopCmd.execute(Arrays.asList(Constants.FN_JOB, "-name", "job_test", "-unknownOption"));
+      fail("Stop command should fail as unknown option encountered!");
+    } catch (Exception e) {
+      assertTrue(e.getMessage().contains("Unknown option encountered"));
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c40c23c9/shell/src/test/java/org/apache/sqoop/shell/TestUpdateCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/sqoop/shell/TestUpdateCommand.java b/shell/src/test/java/org/apache/sqoop/shell/TestUpdateCommand.java
index 7fd39b9..469ded7 100644
--- a/shell/src/test/java/org/apache/sqoop/shell/TestUpdateCommand.java
+++ b/shell/src/test/java/org/apache/sqoop/shell/TestUpdateCommand.java
@@ -295,6 +295,16 @@ public class TestUpdateCommand {
     assertEquals(job.getDriverConfig().getDateTimeInput("driverConfig.DateTime").getValue().getMillis(),
7654321);
   }
 
+  @Test
+  public void testUnknowOption() {
+    try {
+      updateCmd.execute(Arrays.asList(Constants.FN_JOB, "-name", "job_test", "-unknownOption"));
+      fail("Update command should fail as unknown option encountered!");
+    } catch (Exception e) {
+      assertTrue(e.getMessage().contains("Unknown option encountered"));
+    }
+  }
+
   @SuppressWarnings("unchecked")
   private List<MConfig> getConfig(String configName) {
     List<MInput<?>> list = new ArrayList<MInput<?>>();

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c40c23c9/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java
----------------------------------------------------------------------
diff --git a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java
index 6958ee1..a3d490c 100644
--- a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java
+++ b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java
@@ -22,16 +22,15 @@ import java.io.BufferedWriter;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.log4j.Logger;
+import org.apache.sqoop.cli.SqoopGnuParser;
 import org.apache.sqoop.common.VersionInfo;
 import org.apache.sqoop.connector.ConnectorManager;
 import org.apache.sqoop.json.JobsBean;
@@ -41,7 +40,6 @@ import org.apache.sqoop.model.MLink;
 import org.apache.sqoop.repository.Repository;
 import org.apache.sqoop.repository.RepositoryManager;
 import org.apache.sqoop.tools.ConfiguredTool;
-import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 
 /**
@@ -66,7 +64,7 @@ public class RepositoryDumpTool extends ConfiguredTool {
             .withLongOpt("output")
             .create('o'));
 
-    CommandLineParser parser = new GnuParser();
+    CommandLineParser parser = new SqoopGnuParser();
 
     try {
       CommandLine line = parser.parse(options, arguments);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c40c23c9/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryLoadTool.java
----------------------------------------------------------------------
diff --git a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryLoadTool.java b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryLoadTool.java
index 748ef80..75ef74d 100644
--- a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryLoadTool.java
+++ b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryLoadTool.java
@@ -26,13 +26,13 @@ import java.util.*;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.IOUtils;
 import org.apache.log4j.Logger;
+import org.apache.sqoop.cli.SqoopGnuParser;
 import org.apache.sqoop.common.Direction;
 import org.apache.sqoop.common.VersionInfo;
 import org.apache.sqoop.connector.ConnectorManager;
@@ -84,7 +84,7 @@ public class RepositoryLoadTool extends ConfiguredTool {
     options.addOption(OptionBuilder.isRequired().hasArg().withArgName("filename")
         .withLongOpt("input").create('i'));
 
-    CommandLineParser parser = new GnuParser();
+    CommandLineParser parser = new SqoopGnuParser();
 
     try {
       CommandLine line = parser.parse(options, arguments);


Mime
View raw message