@Test
  public void testCreateUpgradeDowngradeCycleAdvertisingVersion() throws Exception {
    Cluster cluster = clusters.getCluster("c1");
    Service service = cluster.addService("STORM", repoVersionEntity2110);

    ServiceComponent component = service.addServiceComponent("DRPC_SERVER");
    ServiceComponentHost sch = component.addServiceComponentHost("h1");
    sch.setVersion("2.1.1.0");

    ResourceProvider upgradeResourceProvider = createProvider(amc);

    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, String.valueOf(repoVersionEntity2200.getId()));
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());

    Map<String, String> requestInfoProperties = new HashMap<>();

    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties);

    RequestStatus status = upgradeResourceProvider.createResources(request);
    assertEquals(1, status.getAssociatedResources().size());

    Resource r = status.getAssociatedResources().iterator().next();
    String id = r.getPropertyValue("Upgrade/request_id").toString();

    component = service.getServiceComponent("DRPC_SERVER");
    assertNotNull(component);
    assertEquals("2.2.0.0", component.getDesiredVersion());

    ServiceComponentHost hostComponent = component.getServiceComponentHost("h1");
    assertEquals(UpgradeState.IN_PROGRESS, hostComponent.getUpgradeState());

    // !!! can't start a downgrade until cancelling the previous upgrade
    abortUpgrade(Long.parseLong(id));

    requestProps.clear();
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name());

    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties);
    status = upgradeResourceProvider.createResources(request);

    component = service.getServiceComponent("DRPC_SERVER");
    assertNotNull(component);
    assertEquals(repoVersionEntity2110, component.getDesiredRepositoryVersion());

    hostComponent = component.getServiceComponentHost("h1");
    assertEquals(UpgradeState.NONE, hostComponent.getUpgradeState());
    assertEquals("UNKNOWN", hostComponent.getVersion());
  }
Exercises that a component that goes from upgrade->downgrade that switches
{@code versionAdvertised} between will go to UKNOWN. This exercises
{@link UpgradeHelper#updateDesiredRepositoriesAndConfigs(UpgradeContext)}

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java