@Before
  public void setup() throws Exception {
    m_injector = EasyMock.createMock(Injector.class);
    m_clusters = EasyMock.createMock(Clusters.class);
    agentConfigsHolder = createMock(AgentConfigsHolder.class);
    cluster = EasyMock.createMock(Cluster.class);

    Map<String, String> mockYarnProperties = new HashMap<String, String>() {
      {
        put(YARN_NM_PMEM_MB_PROPERTY_NAME, "20480");
      }
    };

    Config yarnConfig = EasyMock.createNiceMock(Config.class);
    expect(yarnConfig.getType()).andReturn(YARN_SITE_CONFIG_TYPE).anyTimes();
    expect(yarnConfig.getProperties()).andReturn(mockYarnProperties).anyTimes();
    expect(cluster.getDesiredConfigByType(YARN_SITE_CONFIG_TYPE)).andReturn(yarnConfig).anyTimes();

    Map<String, String> mockHbaseEnvProps =
        new HashMap<String, String>() {{
          put(YARN_HBASE_SYSTEM_SERVICE_LAUNCH_PROPERTY_NAME, "false");
          put(YARN_HBASE_SYSTEM_SERVICE_QUEUE_PROPERTY_NAME, YARN_DEFAULT_QUEUE);
        }};
    Config hbaseEnvConfig = EasyMock.createNiceMock(Config.class);
    expect(hbaseEnvConfig.getType()).andReturn(YARN_HBASE_ENV_CONFIG_TYPE).anyTimes();
    expect(hbaseEnvConfig.getProperties()).andReturn(mockHbaseEnvProps).anyTimes();
    expect(cluster.getDesiredConfigByType(YARN_HBASE_ENV_CONFIG_TYPE)).andReturn(hbaseEnvConfig).anyTimes();


    Map<String, String> mockYarnEnvProps =
        new HashMap<String, String>() {{
          put(YARN_SYSTEM_SERVICE_USER_NAME, ats_user);
        }};
    Config yarnEnvConfig = EasyMock.createNiceMock(Config.class);
    expect(yarnEnvConfig.getType()).andReturn(YARN_ENV_CONFIG_TYPE).anyTimes();
    expect(yarnEnvConfig.getProperties()).andReturn(mockYarnEnvProps).anyTimes();
    expect(cluster.getDesiredConfigByType(YARN_ENV_CONFIG_TYPE)).andReturn(yarnEnvConfig).anyTimes();

    Map<String, String> mockCsProps =
        new HashMap<String, String>() {{
          put(CAPACITY_SCHEDULER_ROOT_QUEUES, YARN_DEFAULT_QUEUE);
        }};
    Config yarnCsConfig = EasyMock.createNiceMock(Config.class);
    expect(yarnCsConfig.getType()).andReturn(CAPACITY_SCHEDULER_CONFIG_TYPE).anyTimes();
    expect(yarnCsConfig.getProperties()).andReturn(mockCsProps).anyTimes();
    expect(cluster.getDesiredConfigByType(CAPACITY_SCHEDULER_CONFIG_TYPE)).andReturn(yarnCsConfig).anyTimes();



    expect(m_clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes();
    expect(m_injector.getInstance(Clusters.class)).andReturn(m_clusters).atLeastOnce();
    expect(cluster.getClusterId()).andReturn(1L).atLeastOnce();
    expect(cluster.getHosts()).andReturn(Collections.emptyList()).atLeastOnce();

    hosts = Mockito.mock(Set.class);
    service = Mockito.mock(Service.class);
    serviceComponent = Mockito.mock(ServiceComponent.class);
    expect(cluster.getService("YARN")).andReturn(service);
    Mockito.when(service.getServiceComponent("NODEMANAGER")).thenReturn(serviceComponent);


    agentConfigsHolder.updateData(eq(1L), eq(Collections.emptyList()));
    expectLastCall().atLeastOnce();

    replay(m_injector, m_clusters, yarnConfig, hbaseEnvConfig, yarnEnvConfig, yarnCsConfig, agentConfigsHolder);

    clusterField =
        AbstractUpgradeServerAction.class.getDeclaredField("m_clusters");
    clusterField.setAccessible(true);
    agentConfigsHolderField = AbstractUpgradeServerAction.class.getDeclaredField("agentConfigsHolder");
    agentConfigsHolderField.setAccessible(true);
  }
Tests upgrade-related server side actions for YarnConfigCalculation
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/YarnNodeManagerCapacityCalculationTest.java