@Test
  public void testPatchUpgrade() throws Exception {
    UpgradeHelper upgradeHelper = createNiceMock(UpgradeHelper.class);
    ConfigHelper configHelper = createNiceMock(ConfigHelper.class);
    UpgradePack upgradePack = createNiceMock(UpgradePack.class);
    AmbariMetaInfo ami = createNiceMock(AmbariMetaInfo.class);

    expect(m_clusterVersionSummary.getAvailableServiceNames()).andReturn(
        Sets.newHashSet(HDFS_SERVICE_NAME)).once();

    expect(m_targetRepositoryVersion.getType()).andReturn(RepositoryType.PATCH).atLeastOnce();
    expect(m_targetRepositoryVersion.getRepositoryXml()).andReturn(m_vdfXml).once();

    expect(upgradeHelper.suggestUpgradePack(EasyMock.anyString(), EasyMock.anyObject(StackId.class),
        EasyMock.anyObject(StackId.class), EasyMock.anyObject(Direction.class),
        EasyMock.anyObject(UpgradeType.class), EasyMock.anyString())).andReturn(upgradePack).once();

    // make the cluster have 2 services just for fun (the VDF only has 1
    // service)
    expect(m_cluster.getService(ZOOKEEPER_SERVICE_NAME)).andReturn(m_zookeeperService).anyTimes();
    m_services.put(ZOOKEEPER_SERVICE_NAME, m_zookeeperService);
    assertEquals(2, m_services.size());

    replayAll();

    Map<String, Object> requestMap = new HashMap<>();
    requestMap.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.NON_ROLLING.name());
    requestMap.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());
    requestMap.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, m_targetRepositoryVersion.getId().toString());
    requestMap.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");

    UpgradeContext context = new UpgradeContext(m_cluster, requestMap, null, upgradeHelper,
        m_upgradeDAO, m_repositoryVersionDAO, configHelper, ami);

    assertEquals(Direction.UPGRADE, context.getDirection());
    assertEquals(RepositoryType.PATCH, context.getOrchestrationType());
    assertEquals(1, context.getSupportedServices().size());
    assertFalse(context.isPatchRevert());
    assertTrue(context.getUpgradeSummary().isSwitchBits);

    verifyAll();
  }
Tests that the {@link UpgradeContext} for a patch upgrade.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/stack/upgrade/orchestrate/UpgradeContextTest.java