SENTRY-1039: Sentry shell tests assume order of option group privileges (Gregory Chanan, reviewed by Lenni Kuff)
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
index 354cf35..6405bc9 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
@@ -30,6 +30,7 @@
 import java.io.FileOutputStream;
 import java.io.PrintStream;
 import java.security.PrivilegedExceptionAction;
+import java.util.Iterator;
 import java.util.Set;
 import javax.security.auth.Subject;
 
@@ -415,10 +416,16 @@
         // test: command option is required for shell
         args = new String[] {"-conf", confPath.getAbsolutePath() };
         sentryShell = new SentryShellSolr();
-        validateMissingParameterMsg(sentryShell, args,
-                SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[-arg Add group to role," +
-                        " -cr Create role, -rpr Revoke privilege from role, -drg Delete group from role," +
-                        " -lr List role, -lp List privilege, -gpr Grant privilege to role, -dr Drop role]");
+        validateMissingParameterMsgsContains(sentryShell, args,
+                SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[",
+                "-arg Add group to role",
+                "-cr Create role",
+                "-rpr Revoke privilege from role",
+                "-drg Delete group from role",
+                "-lr List role",
+                "-lp List privilege",
+                "-gpr Grant privilege to role",
+                "-dr Drop role");
 
         // clear the test data
         client.dropRole(requestorName, TEST_ROLE_NAME_1, SOLR);
@@ -443,4 +450,26 @@
     Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
     assertTrue(errorMsgs.contains(exceptedErrorMsg));
   }
+
+  private void validateMissingParameterMsgsContains(SentryShellSolr sentryShell, String[] args,
+      String ... expectedErrorMsgsContains) throws Exception {
+    Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
+    boolean foundAllMessages = false;
+    Iterator<String> it = errorMsgs.iterator();
+    while (it.hasNext()) {
+      String errorMessage = it.next();
+      boolean missingExpected = false;
+      for (String expectedContains : expectedErrorMsgsContains) {
+        if (!errorMessage.contains(expectedContains)) {
+          missingExpected = true;
+          break;
+        }
+      }
+      if (!missingExpected) {
+        foundAllMessages = true;
+        break;
+      }
+    }
+    assertTrue(foundAllMessages);
+  }
 }
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java
index 3907200..7883929 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java
@@ -26,6 +26,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
+import java.util.Iterator;
 import java.util.Set;
 
 import junit.framework.Assert;
@@ -552,10 +553,16 @@
         // test: command option is required for shell
         args = new String[] {"-conf", confPath.getAbsolutePath() };
         sentryShell = new SentryShellHive();
-        validateMissingParameterMsg(sentryShell, args,
-                SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[-arg Add group to role," +
-                        " -cr Create role, -rpr Revoke privilege from role, -drg Delete group from role," +
-                        " -lr List role, -lp List privilege, -gpr Grant privilege to role, -dr Drop role]");
+        validateMissingParameterMsgsContains(sentryShell, args,
+                SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[",
+                "-arg Add group to role",
+                "-cr Create role",
+                "-rpr Revoke privilege from role",
+                "-drg Delete group from role",
+                "-lr List role",
+                "-lp List privilege",
+                "-gpr Grant privilege to role",
+                "-dr Drop role");
 
         // clear the test data
         client.dropRole(requestorName, TEST_ROLE_NAME_1);
@@ -580,4 +587,26 @@
     Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
     Assert.assertTrue(errorMsgs.contains(exceptedErrorMsg));
   }
+
+  private void validateMissingParameterMsgsContains(SentryShellHive sentryShell, String[] args,
+      String ... expectedErrorMsgsContains) throws Exception {
+    Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
+    boolean foundAllMessages = false;
+    Iterator<String> it = errorMsgs.iterator();
+    while (it.hasNext()) {
+      String errorMessage = it.next();
+      boolean missingExpected = false;
+      for (String expectedContains : expectedErrorMsgsContains) {
+        if (!errorMessage.contains(expectedContains)) {
+          missingExpected = true;
+          break;
+        }
+      }
+      if (!missingExpected) {
+        foundAllMessages = true;
+        break;
+      }
+    }
+    assertTrue(foundAllMessages);
+  }
 }