@Test
  public void testAddComponentDuringUpgrade() throws Exception {
    expect(m_mockCluster.getService(NEW_SERVICE)).andReturn(m_mockCandidateService).once();
    expect(m_mockCandidateService.getServiceComponent(NEW_COMPONENT)).andThrow(new ServiceComponentNotFoundException(CLUSTER_NAME, NEW_SERVICE, NEW_COMPONENT));
    expect(m_mockCandidateService.addServiceComponent(NEW_COMPONENT)).andReturn(m_mockCandidateServiceComponent).once();

    expect(m_mockHost.getHostName()).andReturn(CANDIDATE_HOST_NAME).atLeastOnce();

    m_mockCandidateServiceComponent.setDesiredState(State.INSTALLED);
    expectLastCall().once();

    Map<String, ServiceComponentHost> existingSCHs = new HashMap<>();
    expect(m_mockCandidateServiceComponent.getServiceComponentHosts()).andReturn(existingSCHs).once();

    ServiceComponentHost mockServiceComponentHost = createNiceMock(ServiceComponentHost.class);
    expect(m_mockCandidateServiceComponent.addServiceComponentHost(CANDIDATE_HOST_NAME)).andReturn(mockServiceComponentHost).once();
    mockServiceComponentHost.setState(State.INSTALLED);
    expectLastCall().once();

    mockServiceComponentHost.setDesiredState(State.INSTALLED);
    expectLastCall().once();

    mockServiceComponentHost.setVersion(StackVersionListener.UNKNOWN_VERSION);
    expectLastCall().once();

    PowerMock.replay(m_action);
    replayAll();

    m_action.execute(null);

    verifyAll();
  }
Tests that adding a component during upgrade invokes the correct methods.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AddComponentActionTest.java