ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lpus...@apache.org
Subject [07/32] ambari git commit: AMBARI-21677 - Upgrade Pre-Checks Should Take PATCH/SERVICE Types Into Account (jonathanhurley)
Date Mon, 14 Aug 2017 12:02:20 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java
index e3e14d5..ec91e48 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java
@@ -22,28 +22,45 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /* Tests for RangerAuditDbCheck */
-
+@RunWith(MockitoJUnitRunner.class)
 public class RangerAuditDbCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private final RangerAuditDbCheck rangerAuditDbCheck = new RangerAuditDbCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     rangerAuditDbCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -53,24 +70,31 @@ public class RangerAuditDbCheckTest {
     };
     Configuration config = Mockito.mock(Configuration.class);
     rangerAuditDbCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("RANGER", service);
+    m_services.put("RANGER", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(rangerAuditDbCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    services.remove("RANGER");
-    Assert.assertFalse(rangerAuditDbCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    Assert.assertTrue(rangerAuditDbCheck.isApplicable(request));
+
+    m_services.remove("RANGER");
+    Assert.assertFalse(rangerAuditDbCheck.isApplicable(request));
   }
 
   @Test
@@ -107,5 +131,5 @@ public class RangerAuditDbCheckTest {
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
   }
-  
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
index c69c4e5..cfffb8f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
@@ -22,7 +22,6 @@ import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -35,18 +34,24 @@ import java.util.Map;
 
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.controller.internal.URLStreamProvider;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
@@ -86,8 +91,21 @@ public class RangerPasswordCheckTest {
   private RangerPasswordCheck m_rpc = null;
   private URLStreamProvider m_streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
   public void setup() throws Exception {
+    MockitoAnnotations.initMocks(this);
+
     m_configMap.put("policymgr_external_url", RANGER_URL);
     m_configMap.put("admin_username", "admin");
     m_configMap.put("admin_password", "pass");
@@ -129,43 +147,32 @@ public class RangerPasswordCheckTest {
 
     EasyMock.reset(m_streamProvider);
     PowerMockito.whenNew(URLStreamProvider.class).withAnyArguments().thenReturn(m_streamProvider);
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testApplicable() throws Exception {
 
     final Service service = EasyMock.createMock(Service.class);
-
-    Map<String, Service> services = new HashMap<>();
-    services.put("RANGER", service);
+    m_services.put("RANGER", service);
 
     expect(service.getDesiredStackId()).andReturn(new StackId("HDP-2.3")).anyTimes();
 
     Cluster cluster = m_clusters.getCluster("cluster");
     EasyMock.reset(cluster);
-    expect(cluster.getServices()).andReturn(services).anyTimes();
+    expect(cluster.getServices()).andReturn(m_services).anyTimes();
     expect(cluster.getService("RANGER")).andReturn(service).atLeastOnce();
 
     replay(cluster, service);
 
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-2.3"));
-    assertTrue(m_rpc.isApplicable(request));
-
-    request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-2.2"));
-    assertFalse(m_rpc.isApplicable(request));
-
-    EasyMock.reset(cluster, service);
-    expect(cluster.getServices()).andReturn(services).anyTimes();
-    expect(cluster.getService("RANGER")).andReturn(service).atLeastOnce();
-    expect(service.getDesiredStackId()).andReturn(new StackId("WILDSTACK-2.0")).anyTimes();
-    replay(cluster, service);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-2.2"));
     assertTrue(m_rpc.isApplicable(request));
-
   }
 
   @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java
index 327faf9..af016b0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java
@@ -22,29 +22,47 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 
 /* Test for RangerSSLConfigCheck */
+@RunWith(MockitoJUnitRunner.class)
 public class RangerSSLConfigCheckTest {
 
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private final RangerSSLConfigCheck rangerSSLConfigCheck = new RangerSSLConfigCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     rangerSSLConfigCheck.clustersProvider = new Provider<Clusters>() {
       @Override
       public Clusters get() {
@@ -53,25 +71,31 @@ public class RangerSSLConfigCheckTest {
     };
     Configuration config = Mockito.mock(Configuration.class);
     rangerSSLConfigCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("RANGER", service);
+    m_services.put("RANGER", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(rangerSSLConfigCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    services.remove("RANGER");
-    Assert.assertFalse(rangerSSLConfigCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    Assert.assertTrue(rangerSSLConfigCheck.isApplicable(request));
 
+    m_services.remove("RANGER");
+    Assert.assertFalse(rangerSSLConfigCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java
index ce9a68c..5d0ca5f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java
@@ -25,17 +25,23 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -43,14 +49,26 @@ import com.google.inject.Provider;
  * Unit tests for SecondaryNamenodeDeletedCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class SecondaryNamenodeDeletedCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private final HostComponentStateDAO hostComponentStateDAO = Mockito.mock(HostComponentStateDAO.class);
 
   private final SecondaryNamenodeDeletedCheck secondaryNamenodeDeletedCheck = new SecondaryNamenodeDeletedCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     secondaryNamenodeDeletedCheck.clustersProvider = new Provider<Clusters>() {
       @Override
       public Clusters get() {
@@ -68,31 +86,40 @@ public class SecondaryNamenodeDeletedCheckTest {
     secondaryNamenodeDeletedCheck.hostComponentStateDao = hostComponentStateDAO;
     Configuration config = Mockito.mock(Configuration.class);
     secondaryNamenodeDeletedCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("HDFS", service);
+    m_services.put("HDFS", service);
 
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(request));
+
+    request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    PrereqCheckRequest req = new PrereqCheckRequest("cluster");
-    req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
-    Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(req));
+    request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
+    Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(request));
 
-    req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS);
-    Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(req));
+    request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS);
+    Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(request));
 
-    services.remove("HDFS");
-    Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("HDFS");
+    Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
index 55c622e..1df3ed6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
@@ -124,12 +124,13 @@ public class ServicePresenceCheckTest {
     Mockito.when(cluster.getServices()).thenReturn(services);
 
     Map<String, String> checkProperties = new HashMap<>();
-    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
-    checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Atlas2, NewService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME, "Atlas, OldService");
+    checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME, "Atlas2, NewService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
-    Mockito.when(prerequisiteCheckConfig.getCheckProperties(
-        m_check.getClass().getName())).thenReturn(checkProperties);
+    Mockito.when(
+        prerequisiteCheckConfig.getCheckProperties(m_check.getClass().getName())).thenReturn(
+            checkProperties);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
@@ -151,7 +152,7 @@ public class ServicePresenceCheckTest {
     Mockito.when(cluster.getServices()).thenReturn(services);
 
     Map<String, String> checkProperties = new HashMap<>();
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"OldService");
+    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME, "OldService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(
@@ -178,9 +179,9 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"MyServiceOne, MyServiceTwo");
-    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME, "Atlas, OldService");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Atlas2, NewService");
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"RemovedService");
+    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME, "RemovedService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(
@@ -206,7 +207,7 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"Atlas, MyService");
-    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"OldService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME, "OldService");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"NewService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
@@ -236,7 +237,7 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"Atlas, HDFS");
-    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Storm, Ranger");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME, "Storm, Ranger");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Storm2, Ranger2");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
@@ -250,4 +251,4 @@ public class ServicePresenceCheckTest {
     m_check.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheckTest.java
index 636cafe..6577651 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheckTest.java
@@ -18,6 +18,8 @@
 package org.apache.ambari.server.checks;
 
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
@@ -28,12 +30,17 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -41,18 +48,33 @@ import com.google.inject.Provider;
  * Unit tests for ServicesMaintenanceModeCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesMaintenanceModeCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
+    m_services.clear();
+
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2"));
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
@@ -96,12 +118,16 @@ public class ServicesMaintenanceModeCheckTest {
     // We don't bother checking service desired state as it's performed by a separate check
     Mockito.when(service.getDesiredState()).thenReturn(State.UNKNOWN);
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
-    servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    servicesMaintenanceModeCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     Mockito.when(service.getDesiredState()).thenReturn(State.STARTED);
     check = new PrerequisiteCheck(null, null);
-    servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesMaintenanceModeCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java
index f6ad846..a8569cc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java
@@ -22,18 +22,24 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -41,13 +47,25 @@ import com.google.inject.Provider;
  * Unit tests for ServicesMapReduceDistributedCacheCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesMapReduceDistributedCacheCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
   private final ServicesMapReduceDistributedCacheCheck servicesMapReduceDistributedCacheCheck = new ServicesMapReduceDistributedCacheCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     servicesMapReduceDistributedCacheCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -57,32 +75,40 @@ public class ServicesMapReduceDistributedCacheCheckTest {
     };
     Configuration config = Mockito.mock(Configuration.class);
     servicesMapReduceDistributedCacheCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("YARN", service);
+    m_services.put("YARN", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
 
-    Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(request));
 
-    PrereqCheckRequest req = new PrereqCheckRequest("cluster");
-    req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
-    Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(req));
+    request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS);
-    Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(req));
+    request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
+    Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(request));
 
+    request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS);
+    Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(request));
 
-    services.remove("YARN");
-    Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("YARN");
+    Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
index a2a74bd..c7e8fd6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
@@ -23,17 +23,23 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -41,13 +47,25 @@ import com.google.inject.Provider;
  * Unit tests for ServicesNamenodeHighAvailabilityCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesNamenodeHighAvailabilityCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
   private final ServicesNamenodeHighAvailabilityCheck servicesNamenodeHighAvailabilityCheck = new ServicesNamenodeHighAvailabilityCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     servicesNamenodeHighAvailabilityCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -57,24 +75,31 @@ public class ServicesNamenodeHighAvailabilityCheckTest {
     };
     Configuration config = Mockito.mock(Configuration.class);
     servicesNamenodeHighAvailabilityCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("HDFS", service);
+    m_services.put("HDFS", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(servicesNamenodeHighAvailabilityCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Assert.assertTrue(servicesNamenodeHighAvailabilityCheck.isApplicable(request));
 
-    services.remove("HDFS");
-    Assert.assertFalse(servicesNamenodeHighAvailabilityCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("HDFS");
+    Assert.assertFalse(servicesNamenodeHighAvailabilityCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
index d0aad2f..545caf3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
@@ -27,21 +27,24 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
-import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -49,26 +52,35 @@ import com.google.inject.Provider;
  * Unit tests for ServicesNamenodeTruncateCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesNamenodeTruncateCheckTest {
 
   private Clusters m_clusters = EasyMock.createMock(Clusters.class);
   private ServicesNamenodeTruncateCheck m_check = new ServicesNamenodeTruncateCheck();
   private final Map<String, String> m_configMap = new HashMap<>();
-  private RepositoryVersionDAO m_repositoryVersionDAO = EasyMock.createMock(RepositoryVersionDAO.class);
 
-  final RepositoryVersionEntity repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   @Before
   public void setup() throws Exception {
     Cluster cluster = EasyMock.createMock(Cluster.class);
 
     Config config = EasyMock.createMock(Config.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("HDFS", service);
+    m_services.clear();
+    m_services.put("HDFS", service);
 
-    expect(cluster.getServices()).andReturn(services).anyTimes();
+    expect(cluster.getServices()).andReturn(m_services).anyTimes();
     expect(config.getProperties()).andReturn(m_configMap).anyTimes();
     expect(cluster.getService("HDFS")).andReturn(service);
     expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(config).anyTimes();
@@ -87,20 +99,12 @@ public class ServicesNamenodeTruncateCheckTest {
       }
     };
 
-    m_check.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
-      @Override
-      public RepositoryVersionDAO get() {
-        return m_repositoryVersionDAO;
-      }
-    };
-
-    RepositoryVersionEntity rve = EasyMock.createMock(RepositoryVersionEntity.class);
-    expect(rve.getType()).andReturn(RepositoryType.STANDARD).anyTimes();
-    expect(m_repositoryVersionDAO.findByStackNameAndVersion(EasyMock.anyString(), EasyMock.anyString())).andReturn(rve).anyTimes();
-    replay(m_repositoryVersionDAO, rve);
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("HDP-2.2.0.0");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.0"));
 
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("HDP-2.2.0.0");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.0"));
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
 
@@ -109,7 +113,7 @@ public class ServicesNamenodeTruncateCheckTest {
 
     PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
     checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetRepositoryVersion(repositoryVersion);
+    checkRequest.setTargetRepositoryVersion(m_repositoryVersion);
 
     Assert.assertTrue(m_check.isApplicable(checkRequest));
   }
@@ -125,9 +129,9 @@ public class ServicesNamenodeTruncateCheckTest {
     m_configMap.put("dfs.allow.truncate", "true");
     request.setSourceStackId(new StackId("HDP-2.2.4.2"));
 
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("2.2.8.4");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.8.4"));
-    request.setTargetRepositoryVersion(repositoryVersion);
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.8.4");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.8.4"));
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
     check = new PrerequisiteCheck(null, null);
     m_check.perform(check, request);
@@ -142,9 +146,9 @@ public class ServicesNamenodeTruncateCheckTest {
     m_configMap.put("dfs.allow.truncate", "true");
     request.setSourceStackId(new StackId("HDP-2.2.4.2"));
 
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("2.3.8.4");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3.8.4"));
-    request.setTargetRepositoryVersion(repositoryVersion);
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.8.4");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3.8.4"));
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
     check = new PrerequisiteCheck(null, null);
     m_check.perform(check, request);
@@ -155,4 +159,4 @@ public class ServicesNamenodeTruncateCheckTest {
     m_check.perform(check, request);
     assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
index 3eaf890..96eefc1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
@@ -22,18 +22,24 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -41,13 +47,25 @@ import com.google.inject.Provider;
  * Unit tests for ServicesTezDistributedCacheCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesTezDistributedCacheCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
   private final ServicesTezDistributedCacheCheck servicesTezDistributedCacheCheck = new ServicesTezDistributedCacheCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     servicesTezDistributedCacheCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -58,24 +76,31 @@ public class ServicesTezDistributedCacheCheckTest {
     Configuration config = Mockito.mock(Configuration.class);
     servicesTezDistributedCacheCheck.config = config;
 
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("TEZ", service);
+    m_services.put("TEZ", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-    Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(request));
 
     PrereqCheckRequest req = new PrereqCheckRequest("cluster");
+    req.setTargetRepositoryVersion(m_repositoryVersion);
+
     req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
     Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(req));
 
@@ -83,8 +108,8 @@ public class ServicesTezDistributedCacheCheckTest {
     Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(req));
 
 
-    services.remove("TEZ");
-    Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("TEZ");
+    Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesUpCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesUpCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesUpCheckTest.java
index ba0f701..a851919 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesUpCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesUpCheckTest.java
@@ -37,13 +37,17 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.powermock.api.mockito.PowerMockito;
@@ -63,15 +67,31 @@ public class ServicesUpCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
+    MockitoAnnotations.initMocks(this);
+
+    m_services.clear();
+
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2"));
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
@@ -129,24 +149,28 @@ public class ServicesUpCheckTest {
     final Service tezService = Mockito.mock(Service.class);
     final Service amsService = Mockito.mock(Service.class);
 
-    HashMap<String, Service> clusterServices = new HashMap<>();
-    clusterServices.put("HDFS", hdfsService);
-    clusterServices.put("TEZ", tezService);
-    clusterServices.put("AMBARI_METRICS", amsService);
+    m_services.put("HDFS", hdfsService);
+    m_services.put("TEZ", tezService);
+    m_services.put("AMBARI_METRICS", amsService);
 
     Mockito.when(hdfsService.getName()).thenReturn("HDFS");
     Mockito.when(tezService.getName()).thenReturn("TEZ");
     Mockito.when(amsService.getName()).thenReturn("AMBARI_METRICS");
 
+    StackId stackId = new StackId("HDP", "2.2");
+    Mockito.when(hdfsService.getDesiredStackId()).thenReturn(stackId);
+    Mockito.when(tezService.getDesiredStackId()).thenReturn(stackId);
+    Mockito.when(amsService.getDesiredStackId()).thenReturn(stackId);
+
     Mockito.when(hdfsService.isClientOnlyService()).thenReturn(false);
     Mockito.when(tezService.isClientOnlyService()).thenReturn(true);
     Mockito.when(amsService.isClientOnlyService()).thenReturn(false);
 
-    Mockito.when(hdfsService.getDesiredStackId()).thenReturn(new StackId("HDP", "2.2"));
-    Mockito.when(tezService.getDesiredStackId()).thenReturn(new StackId("HDP", "2.2"));
-    Mockito.when(amsService.getDesiredStackId()).thenReturn(new StackId("HDP", "2.2"));
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
 
-    Mockito.when(cluster.getServices()).thenReturn(clusterServices);
+    Mockito.when(cluster.getService("HDFS")).thenReturn(hdfsService);
+    Mockito.when(cluster.getService("TEZ")).thenReturn(tezService);
+    Mockito.when(cluster.getService("AMBARI_METRICS")).thenReturn(amsService);
 
     Mockito.when(ambariMetaInfo.getComponent(Mockito.anyString(), Mockito.anyString(),
         Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<ComponentInfo>() {
@@ -264,8 +288,11 @@ public class ServicesUpCheckTest {
       Mockito.when(hcs.getCurrentState()).thenReturn(State.STARTED);
     }
 
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 2. Change some desired states to STARTED, should still pass
@@ -273,7 +300,7 @@ public class ServicesUpCheckTest {
     Mockito.when(hcsDataNode1.getDesiredState()).thenReturn(State.STARTED);
 
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 3. Ensure that ZKFC and AMS are ignored even if their current state is not STARTED
@@ -282,7 +309,7 @@ public class ServicesUpCheckTest {
     Mockito.when(hcsMetricsMonitor.getCurrentState()).thenReturn(State.INSTALLED);
 
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 4. Change HDFS current states to INSTALLED, should fail.
@@ -290,14 +317,14 @@ public class ServicesUpCheckTest {
     Mockito.when(hcsDataNode1.getCurrentState()).thenReturn(State.INSTALLED);
 
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
     // Case 5. Change HDFS master to STARTED, but one slave to INSTALLED, should pass (2/3 are up).
     Mockito.when(hcsNameNode.getCurrentState()).thenReturn(State.STARTED);
     Mockito.when(hcsDataNode1.getCurrentState()).thenReturn(State.INSTALLED);
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 6. Change HDFS master to STARTED, but 2 slaves to INSTALLED, should fail (2/3 are down)
@@ -305,7 +332,7 @@ public class ServicesUpCheckTest {
     Mockito.when(hcsDataNode1.getCurrentState()).thenReturn(State.INSTALLED);
     Mockito.when(hcsDataNode2.getCurrentState()).thenReturn(State.INSTALLED);
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     Assert.assertTrue(check.getFailReason().indexOf("50%") > -1);
 
@@ -313,7 +340,7 @@ public class ServicesUpCheckTest {
     Mockito.when(host1.getMaintenanceState(Mockito.anyLong())).thenReturn(MaintenanceState.ON);
     Mockito.when(host3.getMaintenanceState(Mockito.anyLong())).thenReturn(MaintenanceState.ON);
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // put everything back to normal, then fail NN
@@ -324,13 +351,13 @@ public class ServicesUpCheckTest {
     Mockito.when(host3.getMaintenanceState(Mockito.anyLong())).thenReturn(MaintenanceState.OFF);
 
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
     // put NN into MM; should still fail since it's a master
     Mockito.when(host1.getMaintenanceState(Mockito.anyLong())).thenReturn(MaintenanceState.ON);
     check = new PrerequisiteCheck(null, null);
-    servicesUpCheck.perform(check, new PrereqCheckRequest("cluster"));
+    servicesUpCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
index 439710f..331223d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
@@ -23,17 +23,23 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -41,13 +47,26 @@ import com.google.inject.Provider;
  * Unit tests for ServicesYarnWorkPreservingCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ServicesYarnWorkPreservingCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
   private final ServicesYarnWorkPreservingCheck servicesYarnWorkPreservingCheck = new ServicesYarnWorkPreservingCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     servicesYarnWorkPreservingCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -57,24 +76,29 @@ public class ServicesYarnWorkPreservingCheckTest {
     };
     Configuration config = Mockito.mock(Configuration.class);
     servicesYarnWorkPreservingCheck.config = config;
+
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("YARN", service);
+    m_services.put("YARN", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(servicesYarnWorkPreservingCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+    Assert.assertTrue(servicesYarnWorkPreservingCheck.isApplicable(request));
 
-   services.remove("YARN");
-    Assert.assertFalse(servicesYarnWorkPreservingCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("YARN");
+    Assert.assertFalse(servicesYarnWorkPreservingCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java
index 39089f3..1441256 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java
@@ -21,28 +21,56 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /**
  * Tests {@link StormShutdownWarning}.
  */
+@RunWith(MockitoJUnitRunner.class)
 public class StormShutdownWarningTest extends EasyMockSupport {
 
   private final String m_clusterName = "c1";
   private final Clusters m_clusters = niceMock(Clusters.class);
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+  @Before
+  public void setup() throws Exception {
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
+  }
+
   /**
    * @throws Exception
    */
@@ -60,18 +88,18 @@ public class StormShutdownWarningTest extends EasyMockSupport {
     final Cluster cluster = niceMock(Cluster.class);
     final Service hive = niceMock(Service.class);
 
-    final Map<String, Service> services = new HashMap<>();
-    services.put("STORM", hive);
+    m_services.put("STORM", hive);
 
     EasyMock.expect(cluster.getClusterId()).andReturn(1L).anyTimes();
 
     EasyMock.expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).anyTimes();
-    EasyMock.expect(cluster.getServices()).andReturn(services).atLeastOnce();
+    EasyMock.expect(cluster.getServices()).andReturn(m_services).anyTimes();
     EasyMock.expect(m_clusters.getCluster(m_clusterName)).andReturn(cluster).atLeastOnce();
 
     PrereqCheckRequest request = niceMock(PrereqCheckRequest.class);
-    EasyMock.expect(request.getClusterName()).andReturn(m_clusterName);
-    EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING);
+    EasyMock.expect(request.getClusterName()).andReturn(m_clusterName).anyTimes();
+    EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING).anyTimes();
+    EasyMock.expect(request.getTargetRepositoryVersion()).andReturn(m_repositoryVersion).anyTimes();
 
     replayAll();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
index 5cb666b..5de4b2a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
@@ -56,7 +56,7 @@ public class YarnTimelineServerStatePreservingCheckTest {
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     m_check.clustersProvider = new Provider<Clusters>() {
 
       @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
index a25ad08..fc3a133 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
@@ -19,34 +19,30 @@
 package org.apache.ambari.server.state;
 
 import java.util.ArrayList;
-import java.util.LinkedList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ClusterNotFoundException;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
 import org.apache.ambari.server.checks.CheckDescription;
-import org.apache.ambari.server.checks.ServicesUpCheck;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.HostVersionDAO;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
-import org.apache.ambari.server.orm.dao.UpgradeDAO;
-import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
-import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.easymock.EasyMock;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
+import org.mockito.runners.MockitoJUnitRunner;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.util.Providers;
+import com.google.inject.Provider;
 
 import junit.framework.Assert;
 
@@ -55,9 +51,41 @@ import junit.framework.Assert;
  * Tests the {@link CheckHelper} class
  * Makes sure that people don't forget to add new checks to registry.
  */
-
+@RunWith(MockitoJUnitRunner.class)
 public class CheckHelperTest {
 
+  private final Clusters clusters = Mockito.mock(Clusters.class);
+
+  private MockCheck m_mockCheck;
+
+  private CheckDescription m_mockCheckDescription = Mockito.mock(CheckDescription.class);
+
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  @Mock
+  private Object m_mockPerform;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+  @Before
+  public void setup() throws Exception {
+    m_mockCheck = new MockCheck();
+
+    Mockito.when(m_mockPerform.toString()).thenReturn("Perform!");
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
+  }
+
   /**
    * Sunny case when applicable.
    */
@@ -66,17 +94,15 @@ public class CheckHelperTest {
     final CheckHelper helper = new CheckHelper();
     Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
-    AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
 
     EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
-    descriptor.perform(EasyMock.<PrerequisiteCheck> anyObject(), EasyMock.<PrereqCheckRequest> anyObject());
-    EasyMock.expectLastCall().times(1);
-    EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(true);
-    EasyMock.replay(descriptor, configuration);
-    updateChecksRegistry.add(descriptor);
-
-    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry, configuration);
-    EasyMock.verify(descriptor);
+    EasyMock.replay(configuration);
+    updateChecksRegistry.add(m_mockCheck);
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    helper.performChecks(request, updateChecksRegistry, configuration);
+
+    Assert.assertEquals(PrereqCheckStatus.PASS, request.getResult(m_mockCheckDescription));
   }
 
   /**
@@ -84,16 +110,28 @@ public class CheckHelperTest {
    */
   @Test
   public void testPreUpgradeCheckNotApplicable() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    final Service service = Mockito.mock(Service.class);
+
+    m_services.put("KAFKA", service);
+
+    Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>());
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
+
     final CheckHelper helper = new CheckHelper();
     Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
-    AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
+
     EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
-    EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(false);
-    EasyMock.replay(descriptor, configuration);
-    updateChecksRegistry.add(descriptor);
-    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry, configuration);
-    EasyMock.verify(descriptor);
+    EasyMock.replay(configuration);
+    updateChecksRegistry.add(m_mockCheck);
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    helper.performChecks(request, updateChecksRegistry, configuration);
+
+
+    Assert.assertEquals(null, request.getResult(m_mockCheckDescription));
   }
 
   /**
@@ -102,20 +140,20 @@ public class CheckHelperTest {
   @Test
   public void testPreUpgradeCheckThrowsException() throws Exception {
     final CheckHelper helper = new CheckHelper();
-    List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
-    AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
     Configuration configuration = EasyMock.createNiceMock(Configuration.class);
+    List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
 
     EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
-    descriptor.perform(EasyMock.<PrerequisiteCheck> anyObject(), EasyMock.<PrereqCheckRequest> anyObject());
-    EasyMock.expectLastCall().andThrow(new AmbariException("error"));
-    EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(true);
-    EasyMock.expect(descriptor.getDescription()).andReturn(CheckDescription.HOSTS_HEARTBEAT).anyTimes();
-    EasyMock.replay(descriptor, configuration);
-    updateChecksRegistry.add(descriptor);
-    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry, configuration);
-    EasyMock.verify(descriptor);
-    Assert.assertEquals(PrereqCheckStatus.FAIL, upgradeChecks.get(0).getStatus());
+    EasyMock.replay(configuration);
+    updateChecksRegistry.add(m_mockCheck);
+
+    // this will cause an exception
+    Mockito.when(m_mockPerform.toString()).thenThrow(new RuntimeException());
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    helper.performChecks(request, updateChecksRegistry, configuration);
+
+    Assert.assertEquals(PrereqCheckStatus.FAIL, request.getResult(m_mockCheckDescription));
   }
 
   /**
@@ -123,98 +161,80 @@ public class CheckHelperTest {
    */
   @Test
   public void testPreUpgradeCheckBypassesFailure() throws Exception {
-    // This mock class extends CheckHelper and overrides the getPrerequisiteChecks method in order to return
-    // a PrerequisiteCheck object whose status is FAIL.
-    final CheckHelperMock helper =  new CheckHelperMock();
+    final CheckHelper helper = new CheckHelper();
     Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
 
-    PrereqCheckRequest checkRequest = EasyMock.createNiceMock(PrereqCheckRequest.class);
     EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(true);
-    EasyMock.expect(checkRequest.getClusterName()).andReturn("c1").anyTimes();
-    EasyMock.replay(checkRequest, configuration);
+    EasyMock.replay(configuration);
+    updateChecksRegistry.add(m_mockCheck);
+
+    // this will cause an exception, triggering the bypass
+    Mockito.when(m_mockPerform.toString()).thenThrow(new RuntimeException());
 
-    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(checkRequest, updateChecksRegistry, configuration);
-    Assert.assertEquals(1, upgradeChecks.size());
-    Assert.assertEquals(PrereqCheckStatus.BYPASS, upgradeChecks.get(0).getStatus());
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    helper.performChecks(request, updateChecksRegistry, configuration);
+
+    Assert.assertEquals(PrereqCheckStatus.BYPASS, request.getResult(m_mockCheckDescription));
   }
 
   @Test
   public void testPreUpgradeCheckClusterMissing() throws Exception {
-    final Clusters clusters = Mockito.mock(Clusters.class);
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    final Service service = Mockito.mock(Service.class);
+
+    m_services.put("KAFKA", service);
+
+    Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>());
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+
+    Mockito.when(clusters.getCluster(Mockito.anyString())).thenReturn(cluster);
+
+    final CheckHelper helper = new CheckHelper();
     Configuration configuration = EasyMock.createNiceMock(Configuration.class);
-    Mockito.when(clusters.getCluster(Mockito.anyString())).thenAnswer(new Answer<Cluster>() {
-      @Override
-      public Cluster answer(InvocationOnMock invocation) throws Throwable {
-        final String clusterName = invocation.getArguments()[0].toString();
-        if (clusterName.equals("existing")) {
-          return Mockito.mock(Cluster.class);
-        } else {
-          throw new ClusterNotFoundException(clusterName);
-        }
-      }
-    });
-
-    final OsFamily osFamily = Mockito.mock(OsFamily.class);
-
-    final Injector injector = Guice.createInjector(new AbstractModule() {
-
-      @Override
-      protected void configure() {
-        bind(Clusters.class).toInstance(clusters);
-        bind(HostVersionDAO.class).toProvider(Providers.<HostVersionDAO>of(null));
-        bind(UpgradeDAO.class).toProvider(Providers.<UpgradeDAO>of(null));
-        bind(RepositoryVersionDAO.class).toProvider(Providers.<RepositoryVersionDAO>of(null));
-        bind(RepositoryVersionHelper.class).toProvider(Providers.<RepositoryVersionHelper>of(null));
-        bind(AmbariMetaInfo.class).toProvider(Providers.<AmbariMetaInfo>of(null));
-        bind(ServicesUpCheck.class).toInstance(new ServicesUpCheck());
-        bind(OsFamily.class).toInstance(osFamily);
-      }
-    });
-
-    final CheckHelper helper = injector.getInstance(CheckHelper.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
 
     EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
-
     EasyMock.replay(configuration);
+    updateChecksRegistry.add(m_mockCheck);
 
-    // mocked Cluster has no services, so the check should always be PASS
-    updateChecksRegistry.add(injector.getInstance(ServicesUpCheck.class));
-    List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("existing"), updateChecksRegistry, configuration);
-    Assert.assertEquals(PrereqCheckStatus.PASS, upgradeChecks.get(0).getStatus());
-    upgradeChecks = helper.performChecks(new PrereqCheckRequest("non-existing"), updateChecksRegistry, configuration);
-    Assert.assertEquals(PrereqCheckStatus.FAIL, upgradeChecks.get(0).getStatus());
-    //non existing cluster is an expected error
-    Assert.assertTrue(!upgradeChecks.get(0).getFailReason().equals("Unexpected server error happened"));
-  }
+    // this will cause an exception, triggering the fail
+    Mockito.when(m_mockPerform.toString()).thenThrow(new RuntimeException());
 
-  class CheckHelperMock extends CheckHelper {
-    @Override
-    public List<DescriptorPreCheck> getApplicablePrerequisiteChecks(PrereqCheckRequest request,
-                                                          List<AbstractCheckDescriptor> checksRegistry) {
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
-      List<DescriptorPreCheck> applicablePreChecks = new LinkedList<>();
+    helper.performChecks(request, updateChecksRegistry, configuration);
 
-      try {
-        CheckDescription description = CheckDescription.SERVICES_UP;
-        PrerequisiteCheck check = new PrerequisiteCheck(description, "c1");
-        check.setStatus(PrereqCheckStatus.FAIL);
+    Assert.assertEquals(PrereqCheckStatus.FAIL, request.getResult(m_mockCheckDescription));
+  }
 
-        AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
-        EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest>anyObject())).andReturn(true);
-        EasyMock.expect(descriptor.getDescription()).andReturn(description).anyTimes();
+  class MockCheck extends AbstractCheckDescriptor {
 
-        // Allow bypassing failures
-        EasyMock.replay(descriptor);
+    protected MockCheck() {
+      super(m_mockCheckDescription);
 
-        applicablePreChecks.add(new DescriptorPreCheck(descriptor, check));
-      } catch (AmbariException e) {
-        ;
-      }
+      clustersProvider = new Provider<Clusters>() {
 
-      return applicablePreChecks;
+        @Override
+        public Clusters get() {
+          return clusters;
+        }
+      };
     }
-  }
-}
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<String> getApplicableServices() {
+      return m_services.keySet();
+    }
+
+    @Override
+    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
+        throws AmbariException {
+      m_mockPerform.toString();
+    }
+  }
+}
\ No newline at end of file


Mime
View raw message