@Test
public void testPerform() throws Exception {

  final Cluster cluster = Mockito.mock(Cluster.class);
  Mockito.when(cluster.getClusterId()).thenReturn(1L);
  Mockito.when(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("mapred-site", desiredConfig);
  configMap.put("core-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);
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  properties.put("fs.defaultFS", "anything");
  properties.put("mapreduce.application.framework.path", "hdfs://some/path");
  properties.put("mapreduce.application.classpath", "anything");
  check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  properties.put("fs.defaultFS", "anything");
  properties.put("mapreduce.application.framework.path", "dfs://some/path");
  properties.put("mapreduce.application.classpath", "anything");
  check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  properties.put("fs.defaultFS", "hdfs://ha");
  properties.put("mapreduce.application.framework.path", "/some/path");
  properties.put("mapreduce.application.classpath", "anything");
  check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  properties.put("fs.defaultFS", "dfs://ha");
  properties.put("mapreduce.application.framework.path", "/some/path");
  properties.put("mapreduce.application.classpath", "anything");
  check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  // Fail due to no dfs
  properties.put("fs.defaultFS", "anything");
  properties.put("mapreduce.application.framework.path", "/some/path");
  properties.put("mapreduce.application.classpath", "anything");
  check = new PrerequisiteCheck(null, null);
  servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
}