[1/3] ambari git commit: AMBARI-21677 - Upgrade Pre-Checks Should Take PATCH/SERVICE Types Into Account (jonathanhurley)

2017-08-09 Thread jonathanhurley
Repository: ambari
Updated Branches:
  refs/heads/trunk b4de62079 -> 108ad9b4a


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 m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
 rangerAuditDbCheck.clustersProvider = new Provider() {
 
   @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 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 

[1/3] ambari git commit: AMBARI-21677 - Upgrade Pre-Checks Should Take PATCH/SERVICE Types Into Account (jonathanhurley)

2017-08-08 Thread jonathanhurley
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-21450 8bf44f3d5 -> 1f95e149b


http://git-wip-us.apache.org/repos/asf/ambari/blob/1f95e149/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 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/1f95e149/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 22f2b1b..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