@Test
public void testPerform() throws Exception {

  final Cluster cluster = Mockito.mock(Cluster.class);
  Mockito.when(cluster.getClusterId()).thenReturn(1L);
  Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
  final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class);
  Mockito.when(desiredConfig.getTag()).thenReturn("tag");
  Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>();
  configMap.put("hive-site", desiredConfig);
  Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap);
  final Config config = Mockito.mock(Config.class);
  Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config);
  final Map<String, String> properties = new HashMap<String, String>();
  Mockito.when(config.getProperties()).thenReturn(properties);
  Map<String, String> checkProperties = new HashMap<String, String>();
  checkProperties.put("min-failure-stack-version","HDP-2.3.0.0");
  PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
  Mockito.when(prerequisiteCheckConfig.getCheckProperties(
      m_check.getClass().getName())).thenReturn(checkProperties);
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  PrereqCheckRequest request = new PrereqCheckRequest("cluster");
  request.setPrerequisiteCheckConfig(prerequisiteCheckConfig);
  // Check HDP-2.2.x => HDP-2.2.y
  request.setSourceStackId(new StackId("HDP-2.2.4.2"));
  request.setTargetStackId(new StackId("HDP-2.2.8.4"));
  m_check.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
  // Check HDP-2.2.x => HDP-2.3.y
  request.setSourceStackId(new StackId("HDP-2.2.4.2"));
  request.setTargetStackId(new StackId("HDP-2.3.8.4"));
  m_check.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Check HDP-2.3.x => HDP-2.3.y
  request.setSourceStackId(new StackId("HDP-2.3.4.2"));
  request.setTargetStackId(new StackId("HDP-2.3.8.4"));
  m_check.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Check HDP-2.3.x => HDP-2.4.y
  request.setSourceStackId(new StackId("HDP-2.3.4.2"));
  request.setTargetStackId(new StackId("HDP-2.4.8.4"));
  m_check.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Check when properties are specified
  properties.put("hive.server2.support.dynamic.service.discovery", "true");
  properties.put("hive.zookeeper.quorum", "host");
  properties.put("hive.server2.zookeeper.namespace", "namespace");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
}