ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject [1/2] ambari git commit: AMBARI-9406. Service configurations are not updated as customized in the descriptor (rlevas)
Date Wed, 04 Feb 2015 01:39:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5ff857cd2 -> d6c389c11


http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index e0667da..6aee03b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -55,7 +55,6 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
 import org.easymock.Capture;
 import org.junit.Before;
 import org.junit.Test;
@@ -536,55 +535,6 @@ public class AmbariManagementControllerImplTest {
   }
 
   /**
-   * Ensure that when the appropriate request directives are set, KerberosHelper#executeCustomOperations
-   * is invoked
-   */
-  @Test
-  public void testUpdateClustersKerberosCustomOperationsInvoked() throws Exception {
-    // member state mocks
-    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
-    Injector injector = createStrictMock(Injector.class);
-    Cluster cluster = createNiceMock(Cluster.class);
-    ActionManager actionManager = createNiceMock(ActionManager.class);
-    ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class);
-
-    // requests
-    Set<ClusterRequest> requests = Collections.singleton(clusterRequest);
-
-    // request properties (aka directives)
-    Map<String, String> requestProperties = Collections.singletonMap("regenerate_keytabs",
"true");
-
-    KerberosHelper kerberosHelper = createMockBuilder(KerberosHelper.class)
-    .addMockedMethod("executeCustomOperations", Cluster.class, KerberosDescriptor.class,
Map.class, RequestStageContainer.class)
-    .createStrictMock();
-
-    // expectations
-    injector.injectMembers(capture(controllerCapture));
-    expect(injector.getInstance(Gson.class)).andReturn(null);
-    expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
-    expect(injector.getInstance(KerberosHelper.class)).andReturn(kerberosHelper);
-    expect(clusterRequest.getClusterId()).andReturn(1L).times(6);
-    expect(clusterRequest.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
-    expect(clusters.getClusterById(1L)).andReturn(cluster).times(2);
-    expect(cluster.getClusterName()).andReturn("cluster").times(2);
-
-    expect(kerberosHelper.executeCustomOperations(cluster, null, requestProperties, null))
-        .andReturn(null)
-        .once();
-
-    // replay mocks
-    replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper);
-
-    // test
-    AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager,
clusters, injector);
-    controller.updateClusters(requests, requestProperties);
-
-    // assert and verify
-    assertSame(controller, controllerCapture.getValue());
-    verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper);
-  }
-
-  /**
    * Ensure that when the cluster is updated KerberosHandler.toggleKerberos is not invoked
unless
    * the security type is altered
    */
@@ -659,7 +609,7 @@ public class AmbariManagementControllerImplTest {
     expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.KERBEROS, null))
         .andReturn(false)
         .once();
-    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(KerberosDescriptor.class), anyObject(RequestStageContainer.class)))
+    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(RequestStageContainer.class)))
         .andReturn(null)
         .once();
 
@@ -709,7 +659,7 @@ public class AmbariManagementControllerImplTest {
     expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE, null))
         .andReturn(false)
         .once();
-    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(KerberosDescriptor.class), anyObject(RequestStageContainer.class)))
+    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(RequestStageContainer.class)))
         .andReturn(null)
         .once();
 
@@ -768,7 +718,7 @@ public class AmbariManagementControllerImplTest {
     expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE, null))
         .andReturn(false)
         .once();
-    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(KerberosDescriptor.class), anyObject(RequestStageContainer.class)))
+    expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class),
anyObject(RequestStageContainer.class)))
         .andThrow(new IllegalArgumentException("bad args!"))
         .once();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index 9cc7bbb..5cf15d8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -62,6 +62,7 @@ import org.apache.ambari.server.state.cluster.ClustersImpl;
 import org.apache.ambari.server.state.host.HostFactory;
 import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
+import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.apache.ambari.server.state.kerberos.KerberosIdentityDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosKeytabDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosPrincipalDescriptor;
@@ -69,14 +70,11 @@ import org.apache.ambari.server.state.kerberos.KerberosPrincipalType;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
+import org.easymock.EasyMockSupport;
 import org.easymock.IAnswer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
 import javax.persistence.EntityManager;
 
@@ -94,27 +92,18 @@ import static org.easymock.EasyMock.anyLong;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.powermock.api.easymock.PowerMock.createMock;
-import static org.powermock.api.easymock.PowerMock.createNiceMock;
-import static org.powermock.api.easymock.PowerMock.createStrictMock;
-import static org.powermock.api.easymock.PowerMock.expectLastCall;
-import static org.powermock.api.easymock.PowerMock.mockStatic;
-import static org.powermock.api.easymock.PowerMock.replay;
-import static org.powermock.api.easymock.PowerMock.replayAll;
-import static org.powermock.api.easymock.PowerMock.reset;
-import static org.powermock.api.easymock.PowerMock.verify;
-import static org.powermock.api.easymock.PowerMock.verifyAll;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(KerberosDescriptor.class)
-@PowerMockIgnore({"javax.crypto.*", "org.apache.log4j.*"})
-@SuppressWarnings("unchecked")
-public class KerberosHelperTest {
+
+public class KerberosHelperTest extends EasyMockSupport {
 
   private static Injector injector;
   private final ClusterController clusterController = createStrictMock(ClusterController.class);
+  private final KerberosDescriptorFactory kerberosDescriptorFactory = createStrictMock(KerberosDescriptorFactory.class);
   private final AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
 
   @Before
@@ -181,6 +170,7 @@ public class KerberosHelperTest {
         bind(ConfigHelper.class).toInstance(createNiceMock(ConfigHelper.class));
         bind(KerberosOperationHandlerFactory.class).toInstance(kerberosOperationHandlerFactory);
         bind(ClusterController.class).toInstance(clusterController);
+        bind(KerberosDescriptorFactory.class).toInstance(kerberosDescriptorFactory);
       }
     });
 
@@ -198,11 +188,10 @@ public class KerberosHelperTest {
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
 
     Cluster cluster = createNiceMock(Cluster.class);
-    KerberosDescriptor kerberosDescriptor = createNiceMock(KerberosDescriptor.class);
     RequestStageContainer requestStageContainer = createNiceMock(RequestStageContainer.class);
 
     replayAll();
-    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, kerberosDescriptor, requestStageContainer);
+    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, requestStageContainer);
     verifyAll();
   }
 
@@ -220,10 +209,8 @@ public class KerberosHelperTest {
     final Cluster cluster = createNiceMock(Cluster.class);
     expect(cluster.getDesiredConfigByType("kerberos-env")).andReturn(kerberosEnvConfig).once();
 
-    final KerberosDescriptor kerberosDescriptor = createNiceMock(KerberosDescriptor.class);
-
     replayAll();
-    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, kerberosDescriptor, null);
+    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, null);
     verifyAll();
   }
 
@@ -242,22 +229,20 @@ public class KerberosHelperTest {
     final Cluster cluster = createNiceMock(Cluster.class);
     expect(cluster.getDesiredConfigByType("krb5-conf")).andReturn(krb5ConfConfig).once();
 
-    final KerberosDescriptor kerberosDescriptor = createNiceMock(KerberosDescriptor.class);
-
     replayAll();
-    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, kerberosDescriptor, null);
+    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, null);
     verifyAll();
   }
 
   @Test
   public void testEnableKerberos() throws Exception {
-    testEnableKerberos(new KerberosCredential("principal", "password", "keytab"), false,
false);
+    testEnableKerberos(new KerberosCredential("principal", "password", "keytab"), true, false);
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEnableKerberosMissingCredentials() throws Exception {
     try {
-      testEnableKerberos(null, false, false);
+      testEnableKerberos(null, true, false);
     } catch (IllegalArgumentException e) {
       Assert.assertTrue(e.getMessage().startsWith("Missing KDC administrator credentials"));
       throw e;
@@ -267,7 +252,7 @@ public class KerberosHelperTest {
   @Test(expected = IllegalArgumentException.class)
   public void testEnableKerberosInvalidCredentials() throws Exception {
     try {
-      testEnableKerberos(new KerberosCredential("invalid_principal", "password", "keytab"),
false, false);
+      testEnableKerberos(new KerberosCredential("invalid_principal", "password", "keytab"),
true, false);
     } catch (IllegalArgumentException e) {
       Assert.assertTrue(e.getMessage().startsWith("Invalid KDC administrator credentials"));
       throw e;
@@ -315,10 +300,9 @@ public class KerberosHelperTest {
     final Cluster cluster = createNiceMock(Cluster.class);
 
     try {
-      kerberosHelper.executeCustomOperations(cluster, createNiceMock(KerberosDescriptor.class),
+      kerberosHelper.executeCustomOperations(cluster,
           Collections.singletonMap("invalid_operation", "false"), null);
-    }
-    catch(Throwable t) {
+    } catch (Throwable t) {
       Assert.fail("Exception should not have been thrown");
     }
   }
@@ -328,14 +312,14 @@ public class KerberosHelperTest {
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
     final Cluster cluster = createNiceMock(Cluster.class);
 
-    kerberosHelper.executeCustomOperations(cluster, createNiceMock(KerberosDescriptor.class),
+    kerberosHelper.executeCustomOperations(cluster,
         Collections.singletonMap("regenerate_keytabs", "false"), null);
     Assert.fail("AmbariException should have failed");
   }
 
   @Test
   public void testRegenerateKeytabs() throws Exception {
-    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), false,
false);
+    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"));
   }
 
   @Test
@@ -535,13 +519,12 @@ public class KerberosHelperTest {
     expect(kerberosDescriptor.getService("SERVICE1")).andReturn(serviceDescriptor1).once();
     expect(kerberosDescriptor.getService("SERVICE2")).andReturn(serviceDescriptor2).once();
 
-    //todo: extract method?
     if (getClusterDescriptor) {
-      // needed to mock the static method fromJson()
       setupGetDescriptorFromCluster(kerberosDescriptor);
     } else if (getStackDescriptor) {
       setupGetDescriptorFromStack(kerberosDescriptor);
     }
+
     final StageFactory stageFactory = injector.getInstance(StageFactory.class);
     expect(stageFactory.createNew(anyLong(), anyObject(String.class), anyObject(String.class),
         anyLong(), anyObject(String.class), anyObject(String.class), anyObject(String.class),
@@ -594,8 +577,7 @@ public class KerberosHelperTest {
     // Needed by infrastructure
     metaInfo.init();
 
-    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, !(getClusterDescriptor
|| getStackDescriptor) ?
-        kerberosDescriptor : null, requestStageContainer);
+    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, requestStageContainer);
 
     verifyAll();
   }
@@ -834,15 +816,12 @@ public class KerberosHelperTest {
     // Needed by infrastructure
     metaInfo.init();
 
-    kerberosHelper.toggleKerberos(cluster, SecurityType.NONE, !(getClusterDescriptor || getStackDescriptor)
?
-        kerberosDescriptor : null, requestStageContainer);
+    kerberosHelper.toggleKerberos(cluster, SecurityType.NONE, requestStageContainer);
 
     verifyAll();
   }
 
-  private void testRegenerateKeytabs(final KerberosCredential kerberosCredential,
-                                     boolean getClusterDescriptor,
-                                     boolean getStackDescriptor) throws Exception {
+  private void testRegenerateKeytabs(final KerberosCredential kerberosCredential) throws
Exception {
 
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
 
@@ -1018,13 +997,8 @@ public class KerberosHelperTest {
     expect(kerberosDescriptor.getService("SERVICE1")).andReturn(serviceDescriptor1).once();
     expect(kerberosDescriptor.getService("SERVICE2")).andReturn(serviceDescriptor2).once();
 
-    //todo: extract method?
-    if (getClusterDescriptor) {
-      // needed to mock the static method fromJson()
-      setupGetDescriptorFromCluster(kerberosDescriptor);
-    } else if (getStackDescriptor) {
-      setupGetDescriptorFromStack(kerberosDescriptor);
-    }
+    setupGetDescriptorFromCluster(kerberosDescriptor);
+
     final StageFactory stageFactory = injector.getInstance(StageFactory.class);
     expect(stageFactory.createNew(anyLong(), anyObject(String.class), anyObject(String.class),
         anyLong(), anyObject(String.class), anyObject(String.class), anyObject(String.class),
@@ -1071,14 +1045,12 @@ public class KerberosHelperTest {
     // Needed by infrastructure
     metaInfo.init();
 
-    kerberosHelper.executeCustomOperations(cluster, !(getClusterDescriptor || getStackDescriptor)
?
-        kerberosDescriptor : null, Collections.singletonMap("regenerate_keytabs", "true"),
requestStageContainer);
+    kerberosHelper.executeCustomOperations(cluster, Collections.singletonMap("regenerate_keytabs",
"true"), requestStageContainer);
 
     verifyAll();
   }
 
   private void setupGetDescriptorFromCluster(KerberosDescriptor kerberosDescriptor) throws
Exception {
-    mockStatic(KerberosDescriptor.class);
     ResourceProvider resourceProvider = createStrictMock(ResourceProvider.class);
     expect(clusterController.ensureResourceProvider(Resource.Type.Artifact)).andReturn(resourceProvider).once();
 
@@ -1098,15 +1070,19 @@ public class KerberosHelperTest {
     expect(resourceProvider.getResources(capture(requestCapture),
         capture(predicateCapture))).andReturn(result).once();
 
-    String artifactData = "kerberos descriptor json";
-    expect(resource.getPropertyValue(ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY)).
-        andReturn(artifactData).once();
+    Map<String, Map<String, Object>> resourcePropertiesMap = createStrictMock(Map.class);
+    expect(resourcePropertiesMap.get(ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY))
+        .andReturn(Collections.<String, Object>emptyMap()).once();
+    expect(resourcePropertiesMap.get(ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY + "/properties"))
+        .andReturn(Collections.<String, Object>emptyMap()).once();
 
-    expect(KerberosDescriptor.fromJSON(artifactData)).andReturn(kerberosDescriptor).once();
+    expect(resource.getPropertiesMap()).andReturn(resourcePropertiesMap).once();
+
+    expect(kerberosDescriptorFactory.createInstance(anyObject(Map.class)))
+        .andReturn(kerberosDescriptor).once();
   }
 
   private void setupGetDescriptorFromStack(KerberosDescriptor kerberosDescriptor) throws
Exception {
-    mockStatic(KerberosDescriptor.class);
     ResourceProvider resourceProvider = createStrictMock(ResourceProvider.class);
     expect(clusterController.ensureResourceProvider(Resource.Type.Artifact)).andReturn(resourceProvider).once();
 
@@ -1310,6 +1286,8 @@ public class KerberosHelperTest {
     expect(kerberosDescriptor.getService("SERVICE1")).andReturn(serviceDescriptor1).once();
     expect(kerberosDescriptor.getService("SERVICE3")).andReturn(serviceDescriptor3).once();
 
+    setupGetDescriptorFromCluster(kerberosDescriptor);
+
     final StageFactory stageFactory = injector.getInstance(StageFactory.class);
     expect(stageFactory.createNew(anyLong(), anyObject(String.class), anyObject(String.class),
         anyLong(), anyObject(String.class), anyObject(String.class), anyObject(String.class),
@@ -1362,7 +1340,7 @@ public class KerberosHelperTest {
     serviceComponentFilter.put("SERVICE3", Collections.singleton("COMPONENT3"));
     serviceComponentFilter.put("SERVICE1", null);
 
-    kerberosHelper.ensureIdentities(cluster, kerberosDescriptor, serviceComponentFilter,
identityFilter, requestStageContainer);
+    kerberosHelper.ensureIdentities(cluster, serviceComponentFilter, identityFilter, requestStageContainer);
 
     verifyAll();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
index 8688e28..e697b99 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
@@ -19,7 +19,6 @@
 package org.apache.ambari.server.controller.internal;
 
 import com.google.inject.Injector;
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.KerberosHelper;
 import org.apache.ambari.server.controller.MaintenanceStateHelper;
@@ -542,7 +541,7 @@ public class HostComponentResourceProviderTest {
         andReturn(provider).anyTimes();
 
     expect(kerberosHelper.isClusterKerberosEnabled(cluster)).andReturn(true).once();
-    expect(kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, null, stageContainer)).
+    expect(kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, stageContainer)).
         andReturn(stageContainer).once();
 
     // replay

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/stack/KerberosDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/stack/KerberosDescriptorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/stack/KerberosDescriptorTest.java
index cf426b0..b784239 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/stack/KerberosDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/stack/KerberosDescriptorTest.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.server.stack;
 
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
+import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.util.Assert;
@@ -32,13 +33,14 @@ import java.net.URL;
  * and services
  */
 public class KerberosDescriptorTest {
+  private static final KerberosDescriptorFactory KERBEROS_DESCRIPTOR_FACTORY = new KerberosDescriptorFactory();
+
   private static File stacksDirectory;
   private static File hdpStackDirectory;
   private static File hdp22StackDirectory;
   private static File hdp22ServicesDirectory;
   private static File commonServicesDirectory;
 
-
   @BeforeClass
   public static void beforeClass() {
     URL rootDirectoryURL = KerberosDescriptorTest.class.getResource("/");
@@ -69,7 +71,7 @@ public class KerberosDescriptorTest {
   @Test
   public void testHDP22HBASEServiceDescriptor() throws IOException {
     File hbaseDirectory = new File(hdp22ServicesDirectory, "HBASE");
-    KerberosDescriptor descriptor = KerberosDescriptor.fromFile(new File(hbaseDirectory,
"kerberos.json"));
+    KerberosDescriptor descriptor = KERBEROS_DESCRIPTOR_FACTORY.createInstance(new File(hbaseDirectory,
"kerberos.json"));
     Assert.notNull(descriptor);
     Assert.notNull(descriptor.getServices());
     Assert.notNull(descriptor.getService("HBASE"));
@@ -78,7 +80,7 @@ public class KerberosDescriptorTest {
   @Test
   public void testHDP22HDFSServiceDescriptor() throws IOException {
     File hdfsDirectory = new File(hdp22ServicesDirectory, "HDFS");
-    KerberosDescriptor descriptor = KerberosDescriptor.fromFile(new File(hdfsDirectory, "kerberos.json"));
+    KerberosDescriptor descriptor = KERBEROS_DESCRIPTOR_FACTORY.createInstance(new File(hdfsDirectory,
"kerberos.json"));
     Assert.notNull(descriptor);
     Assert.notNull(descriptor.getServices());
     Assert.notNull(descriptor.getService("HDFS"));
@@ -87,7 +89,7 @@ public class KerberosDescriptorTest {
   @Test
   public void testHDP22YarnServiceDescriptor() throws IOException {
     File yarnDirectory = new File(hdp22ServicesDirectory, "YARN");
-    KerberosDescriptor descriptor = KerberosDescriptor.fromFile(new File(yarnDirectory, "kerberos.json"));
+    KerberosDescriptor descriptor = KERBEROS_DESCRIPTOR_FACTORY.createInstance(new File(yarnDirectory,
"kerberos.json"));
     Assert.notNull(descriptor);
     Assert.notNull(descriptor.getServices());
     Assert.notNull(descriptor.getService("YARN"));

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 84731f0..61652d1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
@@ -17,6 +17,12 @@
  */
 package org.apache.ambari.server.state;
 
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -57,7 +63,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
-import static org.easymock.EasyMock.*;
 
 
 @RunWith(Enclosed.class)

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/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 e4e9776..7944cd6 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
@@ -22,14 +22,15 @@ import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
 import org.junit.Test;
 
-import java.io.File;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class KerberosDescriptorTest {
+  private static final KerberosDescriptorFactory KERBEROS_DESCRIPTOR_FACTORY = new KerberosDescriptorFactory();
+  private static final KerberosServiceDescriptorFactory KERBEROS_SERVICE_DESCRIPTOR_FACTORY
= new KerberosServiceDescriptorFactory();
+
   public static final String JSON_VALUE =
       "{" +
           "  \"properties\": {" +
@@ -219,7 +220,7 @@ public class KerberosDescriptorTest {
   }
 
   private KerberosDescriptor createFromJSON() throws AmbariException {
-    return KerberosDescriptor.fromJSON(JSON_VALUE);
+    return KERBEROS_DESCRIPTOR_FACTORY.createInstance(JSON_VALUE);
   }
 
   private KerberosDescriptor createFromMap() throws AmbariException {
@@ -251,7 +252,7 @@ public class KerberosDescriptorTest {
   public void testInvalid() {
     // Invalid JSON syntax
     try {
-      KerberosServiceDescriptor.fromJSON(JSON_VALUE + "erroneous text");
+      KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(JSON_VALUE + "erroneous text");
       Assert.fail("Should have thrown AmbariException.");
     } catch (AmbariException e) {
       // This is expected

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6c389c1/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosServiceDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosServiceDescriptorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosServiceDescriptorTest.java
index 9785e54..040d481 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosServiceDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosServiceDescriptorTest.java
@@ -114,6 +114,8 @@ public class KerberosServiceDescriptorTest {
         }
       };
 
+  private static final KerberosServiceDescriptorFactory KERBEROS_SERVICE_DESCRIPTOR_FACTORY
= new KerberosServiceDescriptorFactory();
+
   public static void validateFromJSON(KerberosServiceDescriptor[] serviceDescriptors) {
     Assert.assertNotNull(serviceDescriptors);
     Assert.assertEquals(2, serviceDescriptors.length);
@@ -241,11 +243,11 @@ public class KerberosServiceDescriptorTest {
   }
 
   private KerberosServiceDescriptor createFromJSON() throws AmbariException {
-    return KerberosServiceDescriptor.fromJSON("SERVICE_NAME", JSON_VALUE);
+    return KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstance("SERVICE_NAME", JSON_VALUE);
   }
 
   private KerberosServiceDescriptor[] createMultipleFromJSON() throws AmbariException {
-    return KerberosServiceDescriptor.fromJSON(JSON_VALUE_SERVICES);
+    return KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(JSON_VALUE_SERVICES);
   }
 
   private KerberosServiceDescriptor createFromMap() throws AmbariException {
@@ -255,7 +257,7 @@ public class KerberosServiceDescriptorTest {
   private KerberosServiceDescriptor[] createFromFile() throws IOException {
     URL url = getClass().getClassLoader().getResource("service_level_kerberos.json");
     File file = (url == null) ? null : new File(url.getFile());
-    return KerberosServiceDescriptor.fromFile(file);
+    return KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(file);
   }
 
   @Test
@@ -272,7 +274,7 @@ public class KerberosServiceDescriptorTest {
   public void testInvalid() {
     // Invalid JSON syntax
     try {
-      KerberosServiceDescriptor.fromJSON(JSON_VALUE_SERVICES + "erroneous text");
+      KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(JSON_VALUE_SERVICES + "erroneous
text");
       Assert.fail("Should have thrown AmbariException.");
     } catch (AmbariException e) {
       // This is expected
@@ -282,7 +284,7 @@ public class KerberosServiceDescriptorTest {
 
     // Test missing top-level "services"
     try {
-      KerberosServiceDescriptor.fromJSON(JSON_VALUE);
+      KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(JSON_VALUE);
       Assert.fail("Should have thrown AmbariException.");
     } catch (AmbariException e) {
       // This is expected
@@ -294,7 +296,7 @@ public class KerberosServiceDescriptorTest {
     URL url = getClass().getClassLoader().getResource("service_level_kerberos_invalid.json");
     File file = (url == null) ? null : new File(url.getFile());
     try {
-      KerberosServiceDescriptor.fromFile(file);
+      KERBEROS_SERVICE_DESCRIPTOR_FACTORY.createInstances(file);
       Assert.fail("Should have thrown AmbariException.");
     } catch (AmbariException e) {
       // This is expected


Mime
View raw message