@Test
public void testDowngradeOrchestration() throws Exception {

  Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
  assertTrue(upgrades.containsKey("upgrade_test"));
  UpgradePack upgrade = upgrades.get("upgrade_test");
  assertNotNull(upgrade);
  Cluster cluster = makeCluster();
  UpgradeContext context = m_upgradeContextFactory.create(cluster, UpgradeType.ROLLING,
      Direction.DOWNGRADE, DOWNGRADE_VERSION, new HashMap<String, Object>());
  context.setResolver(m_masterHostResolver);
  List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
  assertEquals(7, groups.size());
  assertEquals("PRE_CLUSTER", groups.get(0).name);
  assertEquals("OOZIE", groups.get(1).name);
  assertEquals("HIVE", groups.get(2).name);
  assertEquals("CORE_SLAVES", groups.get(3).name);
  assertEquals("CORE_MASTER", groups.get(4).name);
  assertEquals("ZOOKEEPER", groups.get(5).name);
  UpgradeGroupHolder postGroup = groups.get(6);
  assertEquals("POST_CLUSTER", postGroup.name);
  assertEquals("Finalize Downgrade", postGroup.title);
  assertEquals(3, postGroup.items.size());
  assertEquals("Confirm Finalize", postGroup.items.get(0).getText());
  assertEquals("Execute HDFS Finalize", postGroup.items.get(1).getText());
  assertEquals("Save Cluster State", postGroup.items.get(2).getText());
  assertEquals(StageWrapper.Type.SERVER_SIDE_ACTION, postGroup.items.get(2).getType());
  assertEquals(4, groups.get(0).items.size());
  assertEquals(8, groups.get(1).items.size());
  assertEquals(5, groups.get(2).items.size());
  assertEquals(8, groups.get(3).items.size());
  assertEquals(8, groups.get(4).items.size());
}