@Test
  public void testUpgradeParsing() throws Exception {
    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
    assertTrue(upgrades.size() > 0);
    assertTrue(upgrades.containsKey("upgrade_test"));
    UpgradePack upgrade = upgrades.get("upgrade_test");
    assertEquals("2.2.*.*", upgrade.getTarget());

    Map<String, List<String>> expectedStages = new LinkedHashMap<String, List<String>>() {{
      put("ZOOKEEPER", Arrays.asList("ZOOKEEPER_SERVER"));
      put("HDFS", Arrays.asList("NAMENODE", "DATANODE"));
    }};

    // !!! test the tasks
    int i = 0;
    for (Entry<String, List<String>> entry : expectedStages.entrySet()) {
      assertTrue(upgrade.getTasks().containsKey(entry.getKey()));
      assertEquals(i++, indexOf(upgrade.getTasks(), entry.getKey()));

      // check that the number of components matches
      assertEquals(entry.getValue().size(), upgrade.getTasks().get(entry.getKey()).size());

      // check component ordering
      int j = 0;
      for (String comp : entry.getValue()) {
        assertEquals(j++, indexOf(upgrade.getTasks().get(entry.getKey()), comp));
      }
    }

    // !!! test specific tasks
    assertTrue(upgrade.getTasks().containsKey("HDFS"));
    assertTrue(upgrade.getTasks().get("HDFS").containsKey("NAMENODE"));

    ProcessingComponent pc = upgrade.getTasks().get("HDFS").get("NAMENODE");
    assertNotNull(pc.preTasks);
    assertNotNull(pc.postTasks);
    assertNotNull(pc.tasks);
    assertNotNull(pc.preDowngradeTasks);
    assertNotNull(pc.postDowngradeTasks);
    assertEquals(1, pc.tasks.size());

    assertEquals(3, pc.preDowngradeTasks.size());
    assertEquals(1, pc.postDowngradeTasks.size());

    assertEquals(Task.Type.RESTART, pc.tasks.get(0).getType());
    assertEquals(RestartTask.class, pc.tasks.get(0).getClass());


    assertTrue(upgrade.getTasks().containsKey("ZOOKEEPER"));
    assertTrue(upgrade.getTasks().get("ZOOKEEPER").containsKey("ZOOKEEPER_SERVER"));

    pc = upgrade.getTasks().get("HDFS").get("DATANODE");
    assertNotNull(pc.preDowngradeTasks);
    assertEquals(0, pc.preDowngradeTasks.size());
    assertNotNull(pc.postDowngradeTasks);
    assertEquals(1, pc.postDowngradeTasks.size());


    pc = upgrade.getTasks().get("ZOOKEEPER").get("ZOOKEEPER_SERVER");
    assertNotNull(pc.preTasks);
    assertEquals(1, pc.preTasks.size());
    assertNotNull(pc.postTasks);
    assertEquals(1, pc.postTasks.size());
    assertNotNull(pc.tasks);
    assertEquals(1, pc.tasks.size());

    pc = upgrade.getTasks().get("YARN").get("NODEMANAGER");
    assertNotNull(pc.preTasks);
    assertEquals(2, pc.preTasks.size());
    Task t = pc.preTasks.get(1);
    assertEquals(ConfigureTask.class, t.getClass());
    ConfigureTask ct = (ConfigureTask) t;
    // check that the Configure task successfully parsed id
    assertEquals("hdp_2_1_1_nm_pre_upgrade", ct.getId());
    assertFalse(ct.supportsPatch);
  }
Tests that boolean values are property serialized in the upgrade pack.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java