Repository: knox
Updated Branches:
  refs/heads/master 2372ea571 -> 10b1ed02e


KNOX-1188: Maintain provider parameter order in generated topologies


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

Branch: refs/heads/master
Commit: 10b1ed02e64561325110ad2ec14fcf9c4532748f
Parents: 2372ea5
Author: Phil Zampino <pzamp...@apache.org>
Authored: Sun Feb 18 21:40:35 2018 -0500
Committer: Phil Zampino <pzamp...@apache.org>
Committed: Sun Feb 18 22:00:51 2018 -0500

----------------------------------------------------------------------
 .../simple/ProviderConfigurationParser.java     |  5 +-
 .../simple/ProviderConfigurationParserTest.java | 64 ++++++++------------
 2 files changed, 28 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/10b1ed02/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
index 4bfc456..4515ff7 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
@@ -34,6 +34,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -170,7 +171,7 @@ public class ProviderConfigurationParser {
 
       @Override
       public Map<String, String> getParams() {
-        Map<String, String> result = new HashMap<>();
+        Map<String, String> result = new LinkedHashMap<>();
         if (params != null) {
           for (XMLParam p : params) {
             result.put(p.name, p.value);
@@ -246,7 +247,7 @@ public class ProviderConfigurationParser {
 
       @Override
       public Map<String, String> getParams() {
-        Map<String, String> result = new HashMap<>();
+        Map<String, String> result = new LinkedHashMap<>();
         if (params != null) {
           result.putAll(params);
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/10b1ed02/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParserTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParserTest.java
 
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParserTest.java
index e8f0a42..b7cdab9 100644
--- 
a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParserTest.java
+++ 
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParserTest.java
@@ -106,7 +106,11 @@ public class ProviderConfigurationParserTest {
         Map<String, String> params = provider.getParams();
         assertNotNull(params);
         assertEquals(3, params.size());
+
+        // KNOX-1188
+        int index = 1;
         for (String name : params.keySet()) {
+          assertEquals("Param out of order", "param" + index++, name);
           assertEquals(name + "-value", params.get(name));
         }
       }
@@ -168,45 +172,7 @@ public class ProviderConfigurationParserTest {
     assertEquals(4, providers.size());
 
     // Validate the providers
-    for (ProviderConfiguration.Provider provider : providers) {
-      String role = provider.getRole();
-      if ("authentication".equals(role)) {
-        assertEquals("ShiroProvider", provider.getName());
-        assertTrue(provider.isEnabled());
-        Map<String, String> params = provider.getParams();
-        assertNotNull(params);
-        assertEquals(8, params.size());
-        assertEquals(params.get("sessionTimeout"), "30");
-        assertEquals(params.get("main.ldapRealm"), 
"org.apache.hadoop.gateway.shirorealm.KnoxLdapRealm");
-        assertEquals(params.get("main.ldapContextFactory"), 
"org.apache.hadoop.gateway.shirorealm.KnoxLdapContextFactory");
-        assertEquals(params.get("main.ldapRealm.contextFactory"), 
"$ldapContextFactory");
-        assertEquals(params.get("main.ldapRealm.userDnTemplate"), 
"uid={0},ou=people,dc=hadoop,dc=apache,dc=org");
-        assertEquals(params.get("main.ldapRealm.contextFactory.url"), 
"ldap://localhost:33389";);
-        
assertEquals(params.get("main.ldapRealm.contextFactory.authenticationMechanism"),
 "simple");
-        assertEquals(params.get("urls./**"), "authcBasic");
-      } else if ("hostmap".equals(role)) {
-        assertEquals("static", provider.getName());
-        assertTrue(provider.isEnabled());
-        Map<String, String> params = provider.getParams();
-        assertNotNull(params);
-        assertEquals(1, params.size());
-        assertEquals(params.get("localhost"), 
"sandbox,sandbox.hortonworks.com");
-      } else if ("ha".equals(role)) {
-        assertEquals("HaProvider", provider.getName());
-        assertFalse(provider.isEnabled());
-        Map<String, String> params = provider.getParams();
-        assertNotNull(params);
-        assertEquals(2, params.size());
-        assertEquals(params.get("WEBHDFS"), 
"maxFailoverAttempts=3;failoverSleep=1000;maxRetryAttempts=300;retrySleep=1000;enabled=true");
-        assertEquals(params.get("HIVE"), 
"maxFailoverAttempts=3;failoverSleep=1000;enabled=true");
-      } else if ("dummy".equals(provider.getRole())) {
-        assertEquals("NoParamsDummyProvider", provider.getName());
-        assertTrue(provider.isEnabled());
-        Map<String, String> params = provider.getParams();
-        assertNotNull(params);
-        assertTrue(params.isEmpty());
-      }
-    }
+    validateParsedProviders(providers);
   }
 
 
@@ -263,6 +229,12 @@ public class ProviderConfigurationParserTest {
     assertEquals(4, providers.size());
 
     // Validate the providers
+    validateParsedProviders(providers);
+  }
+
+
+  private void validateParsedProviders(List<ProviderConfiguration.Provider> 
providers) throws Exception {
+    // Validate the providers
     for (ProviderConfiguration.Provider provider : providers) {
       String role = provider.getRole();
       if ("authentication".equals(role)) {
@@ -279,6 +251,20 @@ public class ProviderConfigurationParserTest {
         assertEquals(params.get("main.ldapRealm.contextFactory.url"), 
"ldap://localhost:33389";);
         
assertEquals(params.get("main.ldapRealm.contextFactory.authenticationMechanism"),
 "simple");
         assertEquals(params.get("urls./**"), "authcBasic");
+
+        // Verify the param order was maintained during parsing (KNOX-1188)
+        String[] expectedParameterOrder = new String[] {"sessionTimeout",
+                                                        "main.ldapRealm",
+                                                        
"main.ldapContextFactory",
+                                                        
"main.ldapRealm.contextFactory",
+                                                        
"main.ldapRealm.userDnTemplate",
+                                                        
"main.ldapRealm.contextFactory.url",
+                                                        
"main.ldapRealm.contextFactory.authenticationMechanism",
+                                                        "urls./**"};
+        int index = 0;
+        for (String name : params.keySet()) {
+          assertEquals("Param out of order", expectedParameterOrder[index++], 
name);
+        }
       } else if ("hostmap".equals(role)) {
         assertEquals("static", provider.getName());
         assertTrue(provider.isEnabled());

Reply via email to