You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2016/09/09 18:52:46 UTC

[3/4] ambari git commit: AMBARI-18335. After upgrading cluster from HDP-2.4.x to HDP-2.5.x and added atlas service - missing kafka security properties (rlevas)

http://git-wip-us.apache.org/repos/asf/ambari/blob/f9abdafa/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterKerberosDescriptorResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterKerberosDescriptorResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterKerberosDescriptorResourceProviderTest.java
index f551b42..1f91915 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterKerberosDescriptorResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterKerberosDescriptorResourceProviderTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import com.google.gson.Gson;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -65,6 +66,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.TreeMap;
 
 import static org.easymock.EasyMock.*;
 
@@ -74,111 +76,105 @@ import static org.easymock.EasyMock.*;
 @SuppressWarnings("unchecked")
 public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSupport {
 
-  private static final Map<String, Object> STACK_MAP =
-      new HashMap<String, Object>() {
-        {
-          put("properties", new HashMap<String, Object>() {{
-            put("realm", "EXAMPLE.COM");
-            put("some.property", "Hello World");
-          }});
-
-          put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), new ArrayList<String>() {{
-            add("global.name.rules");
-          }});
-
-          put(AbstractKerberosDescriptor.Type.SERVICE.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(KerberosServiceDescriptorTest.MAP_VALUE);
-          }});
-          put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), new ArrayList<Map<String, Object>>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("cluster-conf", new HashMap<String, String>() {
-                  {
-                    put("property1", "red");
-                  }
-                });
-              }
-            });
-          }});
-          put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("name", "shared");
-                put("principal", new HashMap<String, Object>(KerberosPrincipalDescriptorTest.MAP_VALUE));
-                put("keytab", new HashMap<String, Object>() {
-                  {
-                    put("file", "/etc/security/keytabs/subject.service.keytab");
-
-                    put("owner", new HashMap<String, Object>() {{
-                      put("name", "root");
-                      put("access", "rw");
-                    }});
-
-                    put("group", new HashMap<String, Object>() {{
-                      put("name", "hadoop");
-                      put("access", "r");
-                    }});
-
-                    put("configuration", "service-site/service2.component.keytab.file");
-                  }
-                });
-              }
-            });
-          }});
-        }
-      };
-
-  private static final Map<String, Object> USER_MAP =
-      new HashMap<String, Object>() {
-        {
-          put("properties", new HashMap<String, Object>() {{
-            put("realm", "HWX.COM");
-            put("some.property", "Hello World");
-          }});
-
-          put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), new ArrayList<Map<String, Object>>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("cluster-conf", new HashMap<String, String>() {
-                  {
-                    put("property1", "blue");
-                    put("property2", "orange");
-                  }
-                });
-              }
-            });
-          }});
-          put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("name", "shared");
-                put("principal", new HashMap<String, Object>(KerberosPrincipalDescriptorTest.MAP_VALUE));
-                put("keytab", new HashMap<String, Object>() {
-                  {
-                    put("file", "/etc/security/keytabs/subject.service.keytab");
-
-                    put("owner", new HashMap<String, Object>() {{
-                      put("name", "root");
-                      put("access", "rw");
-                    }});
-
-                    put("group", new HashMap<String, Object>() {{
-                      put("name", "hadoop");
-                      put("access", "r");
-                    }});
-
-                    put("configuration", "service-site/service2.component.keytab.file");
-                  }
-                });
-              }
-            });
-          }});
-        }
-      };
-
-  private static final Map<String, Object> COMPOSITE_MAP = new HashMap<String, Object>();
+  private static final Gson GSON = new Gson();
+
+  private static final Map<String, Object> STACK_MAP;
+
+  private static final Map<String, Object> USER_MAP;
+
+  private static final Map<String, Object> COMPOSITE_MAP;
 
   static {
+    TreeMap<String, Object> stackProperties = new TreeMap<String, Object>();
+    stackProperties.put("realm", "EXAMPLE.COM");
+    stackProperties.put("some.property", "Hello World");
+
+    Collection<String> authToLocalRules = new ArrayList<String>();
+    authToLocalRules.add("global.name.rules");
+
+    TreeMap<String, Object> stackServices = new TreeMap<String, Object>();
+    stackServices.put((String) KerberosServiceDescriptorTest.MAP_VALUE.get("name"), KerberosServiceDescriptorTest.MAP_VALUE);
+
+    TreeMap<String, Object> stackClusterConfProperties = new TreeMap<String, Object>();
+    stackClusterConfProperties.put("property1", "red");
+
+    TreeMap<String, Object> stackClusterConf = new TreeMap<String, Object>();
+    stackClusterConf.put("cluster-conf", stackClusterConfProperties);
+
+    TreeMap<String, Object> stackConfigurations = new TreeMap<String, Object>();
+    stackConfigurations.put("cluster-conf", stackClusterConf);
+
+    TreeMap<String, Object> stackSharedIdentityKeytabOwner = new TreeMap<String, Object>();
+    stackSharedIdentityKeytabOwner.put("name", "root");
+    stackSharedIdentityKeytabOwner.put("access", "rw");
+
+    TreeMap<String, Object> sharedIdentityKeytabGroup = new TreeMap<String, Object>();
+    sharedIdentityKeytabGroup.put("name", "hadoop");
+    sharedIdentityKeytabGroup.put("access", "r");
+
+    TreeMap<String, Object> stackSharedIdentityKeytab = new TreeMap<String, Object>();
+    stackSharedIdentityKeytab.put("file", "/etc/security/keytabs/subject.service.keytab");
+    stackSharedIdentityKeytab.put("owner", stackSharedIdentityKeytabOwner);
+    stackSharedIdentityKeytab.put("group", sharedIdentityKeytabGroup);
+    stackSharedIdentityKeytab.put("configuration", "service-site/service2.component.keytab.file");
+
+    TreeMap<String, Object> stackSharedIdentity = new TreeMap<String, Object>();
+    stackSharedIdentity.put("name", "shared");
+    stackSharedIdentity.put("principal", new TreeMap<String, Object>(KerberosPrincipalDescriptorTest.MAP_VALUE));
+    stackSharedIdentity.put("keytab", stackSharedIdentityKeytab);
+
+    TreeMap<String, Object> stackIdentities = new TreeMap<String, Object>();
+    stackIdentities.put("shared", stackSharedIdentity);
+
+    STACK_MAP = new TreeMap<String, Object>();
+    STACK_MAP.put("properties", stackProperties);
+    STACK_MAP.put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), authToLocalRules);
+    STACK_MAP.put(AbstractKerberosDescriptor.Type.SERVICE.getDescriptorPluralName(), stackServices.values());
+    STACK_MAP.put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), stackConfigurations.values());
+    STACK_MAP.put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), stackIdentities.values());
+
+    TreeMap<String, Object> userProperties = new TreeMap<String, Object>();
+    userProperties.put("realm", "HWX.COM");
+    userProperties.put("some.property", "Hello World");
+
+    TreeMap<String, Object> userClusterConfProperties = new TreeMap<String, Object>();
+    userClusterConfProperties.put("property1", "blue");
+    userClusterConfProperties.put("property2", "orange");
+
+    TreeMap<String, Object> userClusterConf = new TreeMap<String, Object>();
+    userClusterConf.put("cluster-conf", userClusterConfProperties);
+
+    TreeMap<String, Object> userConfigurations = new TreeMap<String, Object>();
+    userConfigurations.put("cluster-conf", userClusterConf);
+
+    TreeMap<String, Object> userSharedIdentityKeytabOwner = new TreeMap<String, Object>();
+    userSharedIdentityKeytabOwner.put("name", "root");
+    userSharedIdentityKeytabOwner.put("access", "rw");
+
+    TreeMap<String, Object> userSharedIdentityKeytabGroup = new TreeMap<String, Object>();
+    userSharedIdentityKeytabGroup.put("name", "hadoop");
+    userSharedIdentityKeytabGroup.put("access", "r");
+
+    TreeMap<String, Object> userSharedIdentityKeytab = new TreeMap<String, Object>();
+    userSharedIdentityKeytab.put("file", "/etc/security/keytabs/subject.service.keytab");
+    userSharedIdentityKeytab.put("owner", userSharedIdentityKeytabOwner);
+    userSharedIdentityKeytab.put("group", userSharedIdentityKeytabGroup);
+    userSharedIdentityKeytab.put("configuration", "service-site/service2.component.keytab.file");
+
+    TreeMap<String, Object> userSharedIdentity = new TreeMap<String, Object>();
+    userSharedIdentity.put("name", "shared");
+    userSharedIdentity.put("principal", new TreeMap<String, Object>(KerberosPrincipalDescriptorTest.MAP_VALUE));
+    userSharedIdentity.put("keytab", userSharedIdentityKeytab);
+
+    TreeMap<String, Object> userIdentities = new TreeMap<String, Object>();
+    userIdentities.put("shared", userSharedIdentity);
+
+    USER_MAP = new TreeMap<String, Object>();
+    USER_MAP.put("properties", userProperties);
+    USER_MAP.put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), userConfigurations.values());
+    USER_MAP.put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), userIdentities.values());
+
+    COMPOSITE_MAP = new TreeMap<String, Object>();
     COMPOSITE_MAP.putAll(STACK_MAP);
     COMPOSITE_MAP.putAll(USER_MAP);
   }
@@ -396,17 +392,7 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
     results = provider.getResources(request, new AndPredicate(clusterPredicate, typePredicate));
     Assert.assertEquals(1, results.size());
 
-    for (Resource result : results) {
-      Assert.assertEquals("c1", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_CLUSTER_NAME_PROPERTY_ID));
-      Assert.assertEquals("STACK", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_TYPE_PROPERTY_ID));
-
-      // Reconstruct the deconstructed Kerberos Descriptor
-      Map partial1 = result.getPropertiesMap().get(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_DESCRIPTOR_PROPERTY_ID);
-      Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
-      partial1.put("properties", partial2);
-
-      Assert.assertEquals(STACK_MAP, partial1);
-    }
+    testResults("STACK", STACK_MAP, results);
 
     // --------------
     // Get the USER Kerberos Descriptor
@@ -417,17 +403,7 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
     results = provider.getResources(request, new AndPredicate(clusterPredicate, typePredicate));
     Assert.assertEquals(1, results.size());
 
-    for (Resource result : results) {
-      Assert.assertEquals("c1", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_CLUSTER_NAME_PROPERTY_ID));
-      Assert.assertEquals("USER", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_TYPE_PROPERTY_ID));
-
-      // Reconstruct the deconstructed Kerberos Descriptor
-      Map partial1 = result.getPropertiesMap().get(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_DESCRIPTOR_PROPERTY_ID);
-      Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
-      partial1.put("properties", partial2);
-
-      Assert.assertEquals(USER_MAP, partial1);
-    }
+    testResults("USER", USER_MAP, results);
 
     // --------------
     // Get the COMPOSITE Kerberos Descriptor
@@ -438,17 +414,7 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
     results = provider.getResources(request, new AndPredicate(clusterPredicate, typePredicate));
     Assert.assertEquals(1, results.size());
 
-    for (Resource result : results) {
-      Assert.assertEquals("c1", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_CLUSTER_NAME_PROPERTY_ID));
-      Assert.assertEquals("COMPOSITE", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_TYPE_PROPERTY_ID));
-
-      // Reconstruct the deconstructed Kerberos Descriptor
-      Map partial1 = result.getPropertiesMap().get(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_DESCRIPTOR_PROPERTY_ID);
-      Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
-      partial1.put("properties", partial2);
-
-      Assert.assertEquals(COMPOSITE_MAP, partial1);
-    }
+    testResults("COMPOSITE", COMPOSITE_MAP, results);
 
     verifyAll();
   }
@@ -553,7 +519,7 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
       Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
       partial1.put("properties", partial2);
 
-      Assert.assertEquals(STACK_MAP, partial1);
+      Assert.assertEquals(GSON.toJson(STACK_MAP), GSON.toJson(partial1));
     }
 
     // --------------
@@ -574,7 +540,7 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
       Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
       partial1.put("properties", partial2);
 
-      Assert.assertEquals(USER_MAP, partial1);
+      Assert.assertEquals(GSON.toJson(USER_MAP), GSON.toJson(partial1));
     }
 
     // --------------
@@ -586,24 +552,14 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
     results = provider.getResources(request, new AndPredicate(clusterPredicate, typePredicate));
     Assert.assertEquals(1, results.size());
 
-    for (Resource result : results) {
-      Assert.assertEquals("c1", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_CLUSTER_NAME_PROPERTY_ID));
-      Assert.assertEquals("COMPOSITE", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_TYPE_PROPERTY_ID));
-
-      // Reconstruct the deconstructed Kerberos Descriptor
-      Map partial1 = result.getPropertiesMap().get(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_DESCRIPTOR_PROPERTY_ID);
-      Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
-      partial1.put("properties", partial2);
-
-      Assert.assertEquals(COMPOSITE_MAP, partial1);
-    }
+    testResults("COMPOSITE", COMPOSITE_MAP, results);
 
     verifyAll();
 
     List<? extends Collection<String>> capturedValues = captureAdditionalServices.getValues();
     Assert.assertEquals(3, capturedValues.size());
 
-    for(Collection<String> capturedValue: capturedValues) {
+    for (Collection<String> capturedValue : capturedValues) {
       Assert.assertEquals(3, capturedValue.size());
       Assert.assertTrue(capturedValue.contains("HIVE"));
       Assert.assertTrue(capturedValue.contains("PIG"));
@@ -821,5 +777,19 @@ public class ClusterKerberosDescriptorResourceProviderTest extends EasyMockSuppo
 
     verifyAll();
   }
+
+  private void testResults(String type, Map<String, Object> expectedData, Set<Resource> results) {
+    for (Resource result : results) {
+      Assert.assertEquals("c1", result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_CLUSTER_NAME_PROPERTY_ID));
+      Assert.assertEquals(type, result.getPropertyValue(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_TYPE_PROPERTY_ID));
+
+      // Reconstruct the deconstructed Kerberos Descriptor
+      Map partial1 = result.getPropertiesMap().get(ClusterKerberosDescriptorResourceProvider.CLUSTER_KERBEROS_DESCRIPTOR_DESCRIPTOR_PROPERTY_ID);
+      Map partial2 = result.getPropertiesMap().get("KerberosDescriptor/kerberos_descriptor/properties");
+      partial1.put("properties", partial2);
+
+      Assert.assertEquals(GSON.toJson(expectedData), GSON.toJson(partial1));
+    }
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f9abdafa/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosComponentDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosComponentDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosComponentDescriptorTest.java
index b74f417..201d84e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosComponentDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosComponentDescriptorTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -24,11 +24,12 @@ import org.apache.ambari.server.AmbariException;
 import org.junit.Test;
 
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 public class KerberosComponentDescriptorTest {
@@ -51,34 +52,35 @@ public class KerberosComponentDescriptorTest {
           "    ]" +
           "}";
 
-  public static final Map<String, Object> MAP_VALUE =
-      new HashMap<String, Object>() {
-        {
-          put("name", "A_DIFFERENT_COMPONENT_NAME");
-          put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(KerberosIdentityDescriptorTest.MAP_VALUE);
-            add(KerberosIdentityDescriptorTest.MAP_VALUE_ALT);
-            add(KerberosIdentityDescriptorTest.MAP_VALUE_REFERENCE);
-          }});
-          put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), new ArrayList<Map<String, Object>>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("service-site", new HashMap<String, String>() {
-                  {
-                    put("service.component.property1", "red");
-                    put("service.component.property", "green");
-                  }
-                });
-              }
-            });
-          }});
-          put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), new ArrayList<String>() {{
-            add("component.name.rules2");
-          }});
-        }
-      };
-
-  public static void validateFromJSON(KerberosComponentDescriptor componentDescriptor) {
+  static final Map<String, Object> MAP_VALUE;
+
+  static {
+    Map<String, Object> identitiesMap = new TreeMap<String, Object>();
+    identitiesMap.put((String) KerberosIdentityDescriptorTest.MAP_VALUE.get("name"), KerberosIdentityDescriptorTest.MAP_VALUE);
+    identitiesMap.put((String) KerberosIdentityDescriptorTest.MAP_VALUE_ALT.get("name"), KerberosIdentityDescriptorTest.MAP_VALUE_ALT);
+    identitiesMap.put((String) KerberosIdentityDescriptorTest.MAP_VALUE_REFERENCE.get("name"), KerberosIdentityDescriptorTest.MAP_VALUE_REFERENCE);
+
+    Map<String, Object> serviceSiteProperties = new TreeMap<String, Object>();
+    serviceSiteProperties.put("service.component.property1", "red");
+    serviceSiteProperties.put("service.component.property", "green");
+
+    Map<String, Map<String, Object>> serviceSiteMap = new TreeMap<String, Map<String, Object>>();
+    serviceSiteMap.put("service-site", serviceSiteProperties);
+
+    TreeMap<String, Map<String, Map<String, Object>>> configurationsMap = new TreeMap<String, Map<String, Map<String, Object>>>();
+    configurationsMap.put("service-site", serviceSiteMap);
+
+    Collection<String> authToLocalRules = new ArrayList<String>();
+    authToLocalRules.add("component.name.rules2");
+
+    MAP_VALUE = new TreeMap<String, Object>();
+    MAP_VALUE.put("name", "A_DIFFERENT_COMPONENT_NAME");
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), new ArrayList<>(identitiesMap.values()));
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), configurationsMap.values());
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), authToLocalRules);
+  }
+
+  static void validateFromJSON(KerberosComponentDescriptor componentDescriptor) {
     Assert.assertNotNull(componentDescriptor);
     Assert.assertTrue(componentDescriptor.isContainer());
 
@@ -112,7 +114,7 @@ public class KerberosComponentDescriptorTest {
     Assert.assertEquals("component.name.rules1", authToLocalProperties.iterator().next());
   }
 
-  public static void validateFromMap(KerberosComponentDescriptor componentDescriptor) {
+  static void validateFromMap(KerberosComponentDescriptor componentDescriptor) {
     Assert.assertNotNull(componentDescriptor);
     Assert.assertTrue(componentDescriptor.isContainer());
 
@@ -146,7 +148,7 @@ public class KerberosComponentDescriptorTest {
     Assert.assertEquals("component.name.rules2", authToLocalProperties.iterator().next());
   }
 
-  public static void validateUpdatedData(KerberosComponentDescriptor componentDescriptor) {
+  private static void validateUpdatedData(KerberosComponentDescriptor componentDescriptor) {
     Assert.assertNotNull(componentDescriptor);
 
     Assert.assertEquals("A_DIFFERENT_COMPONENT_NAME", componentDescriptor.getName());
@@ -213,9 +215,10 @@ public class KerberosComponentDescriptorTest {
 
   @Test
   public void testToMap() throws AmbariException {
+    Gson gson = new Gson();
     KerberosComponentDescriptor descriptor = createFromMap();
     Assert.assertNotNull(descriptor);
-    Assert.assertEquals(MAP_VALUE, descriptor.toMap());
+    Assert.assertEquals(gson.toJson(MAP_VALUE), gson.toJson(descriptor.toMap()));
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f9abdafa/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosConfigurationDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosConfigurationDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosConfigurationDescriptorTest.java
index 6017fae..4f2a2f5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosConfigurationDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosConfigurationDescriptorTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -45,37 +45,33 @@ public class KerberosConfigurationDescriptorTest {
           "}}" +
           "]";
 
-  private static final Map<String, Map<String, Object>> MAP_SINGLE_VALUE =
-      new HashMap<String, Map<String, Object>>() {
-        {
-          put("configuration-type", new HashMap<String, Object>() {
-            {
-              put("property1", "black");
-              put("property2", "white");
-            }
-          });
-        }
-      };
-
-  private static final Collection<Map<String, Map<String, Object>>> MAP_MULTIPLE_VALUES =
-      new ArrayList<Map<String, Map<String, Object>>>() {
-        {
-          add(MAP_SINGLE_VALUE);
-          add(new HashMap<String, Map<String, Object>>() {
-            {
-              put("configuration-type2", new HashMap<String, Object>() {
-                {
-                  put("property1", "red");
-                  put("property2", "yellow");
-                  put("property3", "green");
-                }
-              });
-            }
-          });
-        }
-      };
+  private static final Map<String, Map<String, Object>> MAP_SINGLE_VALUE;
+  private static final Collection<Map<String, Map<String, Object>>> MAP_MULTIPLE_VALUES;
 
 
+  static {
+    TreeMap<String, Object> configuration_data = new TreeMap<String, Object>();
+    configuration_data.put("property1", "black");
+    configuration_data.put("property2", "white");
+
+    MAP_SINGLE_VALUE = new TreeMap<String, Map<String, Object>>();
+    MAP_SINGLE_VALUE.put("configuration-type", configuration_data);
+
+    TreeMap<String, Object> configurationType2Properties = new TreeMap<String, Object>();
+    configurationType2Properties.put("property1", "red");
+    configurationType2Properties.put("property2", "yellow");
+    configurationType2Properties.put("property3", "green");
+
+    Map<String, Map<String, Object>> configurationType2 = new TreeMap<String, Map<String, Object>>();
+    configurationType2.put("configuration-type2", configurationType2Properties);
+
+    TreeMap<String, Map<String, Map<String, Object>>> multipleValuesMap = new TreeMap<String, Map<String, Map<String, Object>>>();
+    multipleValuesMap.put("configuration-type", MAP_SINGLE_VALUE);
+    multipleValuesMap.put("configuration-type2", configurationType2);
+
+    MAP_MULTIPLE_VALUES = multipleValuesMap.values();
+  }
+
   @Test
   public void testJSONDeserialize() {
     Map<String, Map<String, Object>> jsonData = new Gson().fromJson(JSON_SINGLE_VALUE,

http://git-wip-us.apache.org/repos/asf/ambari/blob/f9abdafa/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
index 9463749..0070e6d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -26,11 +26,12 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 public class KerberosDescriptorTest {
@@ -51,59 +52,57 @@ public class KerberosDescriptorTest {
           "    ]" +
           "}";
 
-  public static final Map<String, Object> MAP_VALUE =
-      new HashMap<String, Object>() {
-        {
-          put("properties", new HashMap<String, Object>() {{
-            put("realm", "EXAMPLE.COM");
-            put("some.property", "Hello World");
-          }});
-
-          put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), new ArrayList<String>() {{
-            add("global.name.rules");
-          }});
-
-          put(AbstractKerberosDescriptor.Type.SERVICE.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(KerberosServiceDescriptorTest.MAP_VALUE);
-          }});
-          put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), new ArrayList<Map<String, Object>>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("cluster-conf", new HashMap<String, String>() {
-                  {
-                    put("property1", "red");
-                  }
-                });
-              }
-            });
-          }});
-          put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), new ArrayList<Object>() {{
-            add(new HashMap<String, Object>() {
-              {
-                put("name", "shared");
-                put("principal", new HashMap<String, Object>(KerberosPrincipalDescriptorTest.MAP_VALUE));
-                put("keytab", new HashMap<String, Object>() {
-                  {
-                    put("file", "/etc/security/keytabs/subject.service.keytab");
-
-                    put("owner", new HashMap<String, Object>() {{
-                      put("name", "root");
-                      put("access", "rw");
-                    }});
-
-                    put("group", new HashMap<String, Object>() {{
-                      put("name", "hadoop");
-                      put("access", "r");
-                    }});
-
-                    put("configuration", "service-site/service2.component.keytab.file");
-                  }
-                });
-              }
-            });
-          }});
-        }
-      };
+  public static final Map<String, Object> MAP_VALUE;
+
+  static {
+    Map<String, Object> keytabOwnerMap = new TreeMap<String, Object>();
+    keytabOwnerMap.put("name", "root");
+    keytabOwnerMap.put("access", "rw");
+
+    Map<String, Object> keytabGroupMap = new TreeMap<String, Object>();
+    keytabGroupMap.put("name", "hadoop");
+    keytabGroupMap.put("access", "r");
+
+    Map<String, Object> keytabMap = new TreeMap<String, Object>();
+    keytabMap.put("file", "/etc/security/keytabs/subject.service.keytab");
+    keytabMap.put("owner", keytabOwnerMap);
+    keytabMap.put("group", keytabGroupMap);
+    keytabMap.put("configuration", "service-site/service2.component.keytab.file");
+
+    Map<String, Object> sharedIdentityMap = new TreeMap<String, Object>();
+    sharedIdentityMap.put("name", "shared");
+    sharedIdentityMap.put("principal", KerberosPrincipalDescriptorTest.MAP_VALUE);
+    sharedIdentityMap.put("keytab", keytabMap);
+
+    Map<String, Object> servicesMap = new TreeMap<String, Object>();
+    servicesMap.put((String) KerberosServiceDescriptorTest.MAP_VALUE.get("name"), KerberosServiceDescriptorTest.MAP_VALUE);
+
+    Map<String, Object> identitiesMap = new TreeMap<String, Object>();
+    identitiesMap.put("shared", sharedIdentityMap);
+
+    Map<String, Object> clusterConfigProperties = new TreeMap<String, Object>();
+    clusterConfigProperties.put("property1", "red");
+
+    Map<String, Map<String, Object>> clusterConfigMap = new TreeMap<String, Map<String, Object>>();
+    clusterConfigMap.put("cluster-conf", clusterConfigProperties);
+
+    TreeMap<String, Map<String, Map<String, Object>>> configurationsMap = new TreeMap<String, Map<String, Map<String, Object>>>();
+    configurationsMap.put("cluster-conf", clusterConfigMap);
+
+    Collection<String> authToLocalRules = new ArrayList<String>();
+    authToLocalRules.add("global.name.rules");
+
+    TreeMap<String, Object> properties = new TreeMap<String, Object>();
+    properties.put("realm", "EXAMPLE.COM");
+    properties.put("some.property", "Hello World");
+
+    MAP_VALUE = new TreeMap<String, Object>();
+    MAP_VALUE.put("properties", properties);
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.AUTH_TO_LOCAL_PROPERTY.getDescriptorPluralName(), authToLocalRules);
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.SERVICE.getDescriptorPluralName(), servicesMap.values());
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.CONFIGURATION.getDescriptorPluralName(), configurationsMap.values());
+    MAP_VALUE.put(AbstractKerberosDescriptor.Type.IDENTITY.getDescriptorPluralName(), identitiesMap.values());
+  }
 
   public static void validateFromJSON(KerberosDescriptor descriptor) {
     Assert.assertNotNull(descriptor);
@@ -307,9 +306,10 @@ public class KerberosDescriptorTest {
 
   @Test
   public void testToMap() throws AmbariException {
+    Gson gson = new Gson();
     KerberosDescriptor descriptor = createFromMap();
     Assert.assertNotNull(descriptor);
-    Assert.assertEquals(MAP_VALUE, descriptor.toMap());
+    Assert.assertEquals(gson.toJson(MAP_VALUE), gson.toJson(descriptor.toMap()));
   }
 
   @Test
@@ -325,7 +325,7 @@ public class KerberosDescriptorTest {
     validateUpdatedData(descriptor);
   }
 
-    @Test
+  @Test
   public void testGetReferencedIdentityDescriptor() throws IOException {
     URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_get_referenced_identity_descriptor.json");
     Assert.assertNotNull(systemResourceURL);
@@ -398,7 +398,7 @@ public class KerberosDescriptorTest {
     KerberosServiceDescriptor serviceDescriptor = descriptor.getService("SERVICE2");
     Assert.assertNotNull(serviceDescriptor);
 
-    KerberosComponentDescriptor componentDescriptor =  serviceDescriptor.getComponent("SERVICE2_COMPONENT1");
+    KerberosComponentDescriptor componentDescriptor = serviceDescriptor.getComponent("SERVICE2_COMPONENT1");
     Assert.assertNotNull(componentDescriptor);
 
     KerberosIdentityDescriptor identity;
@@ -429,8 +429,8 @@ public class KerberosDescriptorTest {
     Assert.assertNotNull(identities);
 
     identityFound = false;
-    for(KerberosIdentityDescriptor identity : identities) {
-      if("service2_stack_reference".equals(identity.getName())) {
+    for (KerberosIdentityDescriptor identity : identities) {
+      if ("service2_stack_reference".equals(identity.getName())) {
 
         // From base identity
         Assert.assertEquals("stack@${realm}", identity.getPrincipalDescriptor().getValue());
@@ -445,15 +445,15 @@ public class KerberosDescriptorTest {
     }
     Assert.assertTrue(identityFound);
 
-    KerberosComponentDescriptor componentDescriptor =  serviceDescriptor.getComponent("SERVICE2_COMPONENT1");
+    KerberosComponentDescriptor componentDescriptor = serviceDescriptor.getComponent("SERVICE2_COMPONENT1");
     Assert.assertNotNull(componentDescriptor);
 
     identities = componentDescriptor.getIdentities(true, null);
     Assert.assertNotNull(identities);
 
     identityFound = false;
-    for(KerberosIdentityDescriptor identity : identities) {
-      if("component1_service2_stack_reference".equals(identity.getName())) {
+    for (KerberosIdentityDescriptor identity : identities) {
+      if ("component1_service2_stack_reference".equals(identity.getName())) {
 
         // From base identity
         Assert.assertEquals("stack@${realm}", identity.getPrincipalDescriptor().getValue());