@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);
  Map<String, Service> services = new HashMap<String, Service>();
  Mockito.when(cluster.getServices()).thenReturn(services);
  final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class);
  Mockito.when(desiredConfig.getTag()).thenReturn("tag");
  Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>();
  configMap.put("hdfs-site", desiredConfig);
  configMap.put("hive-site", desiredConfig);
  configMap.put("oozie-env", 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);
  // Add HDFS
  services.put("HDFS", Mockito.mock(Service.class));
  // Add property that will fail
  properties.put("dfs.client.retry.policy.enabled", "true");
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Change property to pass
  properties.put("dfs.client.retry.policy.enabled", "false");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  // Add HIVE
  services.put("HIVE", Mockito.mock(Service.class));
  // Fail with bad property
  properties.put("hive.metastore.failure.retries", "0");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Add hive retry in order to pass
  properties.put("hive.metastore.failure.retries", "5");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  // Add OOZIE
  services.put("OOZIE", Mockito.mock(Service.class));
  // Fail without property
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Fail without right property
  properties.put("template", "foo bar baz");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  // Pass with right property
  properties.put("content", "foo bar baz -Doozie.connection.retry.count=5 foobarbaz");
  check = new PrerequisiteCheck(null, null);
  m_check.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
}