@Test
public void testPerform() throws Exception {

  ConfigurationMergeCheck cmc = new ConfigurationMergeCheck();
  final RepositoryVersionDAO repositoryVersionDAO = EasyMock.createMock(RepositoryVersionDAO.class);
  expect(repositoryVersionDAO.findByStackNameAndVersion("HDP", "1.0")).andReturn(createFor("1.0")).anyTimes();
  expect(repositoryVersionDAO.findByStackNameAndVersion("HDP", "1.1")).andReturn(createFor("1.1")).anyTimes();
  replay(repositoryVersionDAO);
  cmc.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
    @Override
    public RepositoryVersionDAO get() {
      return repositoryVersionDAO;
    }
  };
  cmc.clustersProvider = new Provider<Clusters>() {
    @Override
    public Clusters get() {
      return clusters;
    }
  };
  cmc.m_mergeHelper = new ConfigMergeHelper();
  Field field = ConfigMergeHelper.class.getDeclaredField("m_clusters");
  field.setAccessible(true);
  field.set(cmc.m_mergeHelper, cmc.clustersProvider);
  final AmbariMetaInfo ami = EasyMock.createMock(AmbariMetaInfo.class);
  field = ConfigMergeHelper.class.getDeclaredField("m_ambariMetaInfo");
  field.setAccessible(true);
  field.set(cmc.m_mergeHelper, new Provider<AmbariMetaInfo>() {
    @Override
    public AmbariMetaInfo get() {
      return ami;
    }
  });
  PropertyInfo pi10 = new PropertyInfo();
  pi10.setFilename(CONFIG_FILE);
  pi10.setName(CONFIG_PROPERTY);
  pi10.setValue("1024");
  PropertyInfo pi11 = new PropertyInfo();
  pi11.setFilename(CONFIG_FILE);
  pi11.setName(CONFIG_PROPERTY);
  pi11.setValue("1024");
  expect(ami.getServiceProperties("HDP", "1.0", "HDFS")).andReturn(
      Collections.singleton(pi10)).anyTimes();
  expect(ami.getServiceProperties("HDP", "1.1", "HDFS")).andReturn(
      Collections.singleton(pi11)).anyTimes();
  expect(ami.getStackProperties(anyObject(String.class), anyObject(String.class))).andReturn(
      Collections.<PropertyInfo>emptySet()).anyTimes();
  replay(ami);
  PrereqCheckRequest request = new PrereqCheckRequest("cluster");
  request.setTargetStackId(stackId_1_0);
  request.setRepositoryVersion("1.1");
  PrerequisiteCheck check = new PrerequisiteCheck(null, "cluster");
  cmc.perform(check, request);
  Assert.assertEquals("Expect no warnings", 0, check.getFailedOn().size());
  check = new PrerequisiteCheck(null, "cluster");
  m_configMap.put(CONFIG_PROPERTY, "1025m");
  pi11.setValue("1026");
  cmc.perform(check, request);
  Assert.assertEquals("Expect warning when user-set has changed from new default",
      1, check.getFailedOn().size());
  Assert.assertEquals(1, check.getFailedDetail().size());
  ConfigurationMergeCheck.MergeDetail detail = (ConfigurationMergeCheck.MergeDetail) check.getFailedDetail().get(0);
  Assert.assertEquals("1025m", detail.current);
  Assert.assertEquals("1026m", detail.new_stack_value);
  Assert.assertEquals("1025m", detail.result_value);
  Assert.assertEquals(CONFIG_TYPE, detail.type);
  Assert.assertEquals(CONFIG_PROPERTY, detail.property);
  check = new PrerequisiteCheck(null, "cluster");
  pi11.setName(CONFIG_PROPERTY + ".foo");
  cmc.perform(check, request);
  Assert.assertEquals("Expect no warning when user new stack is empty",
      0, check.getFailedOn().size());
  Assert.assertEquals(0, check.getFailedDetail().size());
  check = new PrerequisiteCheck(null, "cluster");
  pi11.setName(CONFIG_PROPERTY);
  pi10.setName(CONFIG_PROPERTY + ".foo");
  cmc.perform(check, request);
  Assert.assertEquals("Expect warning when user old stack is empty, and value changed",
      1, check.getFailedOn().size());
  Assert.assertEquals(1, check.getFailedDetail().size());
  detail = (ConfigurationMergeCheck.MergeDetail) check.getFailedDetail().get(0);
  Assert.assertEquals("1025m", detail.current);
  Assert.assertEquals("1026m", detail.new_stack_value);
}