@Before
  public void before() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(
        TestAuthenticationFactory.createAdministrator());

    // setup the config helper for placeholder resolution
    configHelper = EasyMock.createNiceMock(ConfigHelper.class);

    expect(
        configHelper.getPlaceholderValueFromDesiredConfigurations(
            EasyMock.anyObject(Cluster.class), EasyMock.eq("{{foo/bar}}"))).andReturn(
        "placeholder-rendered-properly").anyTimes();

    expect(
        configHelper.getDefaultProperties(EasyMock.anyObject(StackId.class),
            EasyMock.anyString())).andReturn(
        new HashMap<>()).anyTimes();

    expect(
        configHelper.getChangedConfigTypes(EasyMock.anyObject(Cluster.class), EasyMock.anyObject(ServiceConfigEntity.class),
            EasyMock.anyLong(), EasyMock.anyLong(), EasyMock.anyString())).andReturn(
        Collections.emptyMap()).anyTimes();
    replay(configHelper);

    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();

    // create an injector which will inject the mocks
    injector = Guice.createInjector(
        Modules.override(module).with(new MockModule()));

    H2DatabaseCleaner.resetSequences(injector);
    injector.getInstance(GuiceJpaInitializer.class);

    amc = injector.getInstance(AmbariManagementController.class);
    configFactory = injector.getInstance(ConfigFactory.class);

    Field field = AmbariServer.class.getDeclaredField("clusterController");
    field.setAccessible(true);
    field.set(null, amc);

    stackDAO = injector.getInstance(StackDAO.class);
    upgradeDao = injector.getInstance(UpgradeDAO.class);
    requestDao = injector.getInstance(RequestDAO.class);
    repoVersionDao = injector.getInstance(RepositoryVersionDAO.class);
    hrcDAO = injector.getInstance(HostRoleCommandDAO.class);

    AmbariEventPublisher publisher = EasyMock.createNiceMock(AmbariEventPublisher.class);
    replay(publisher);
    ViewRegistry.initInstance(new ViewRegistry(publisher));

    // TODO AMARI-12698, this file is attempting to check RU on version 2.1.1, which doesn't support it
    // because it has no upgrade packs. We should use correct versions that have stacks.
    // For now, Ignore the tests that fail.
    StackEntity stackEntity211 = stackDAO.find("HDP", "2.1.1");
    StackEntity stackEntity220 = stackDAO.find("HDP", "2.2.0");
    StackId stack211 = new StackId(stackEntity211);

    repoVersionEntity2110 = new RepositoryVersionEntity();
    repoVersionEntity2110.setDisplayName("My New Version 1");
    repoVersionEntity2110.addRepoOsEntities(createTestOperatingSystems());
    repoVersionEntity2110.setStack(stackEntity211);
    repoVersionEntity2110.setVersion("2.1.1.0");
    repoVersionDao.create(repoVersionEntity2110);

    repoVersionEntity2111 = new RepositoryVersionEntity();
    repoVersionEntity2111.setDisplayName("My New Version 2 for minor upgrade");
    repoVersionEntity2111.addRepoOsEntities(createTestOperatingSystems());
    repoVersionEntity2111.setStack(stackEntity211);
    repoVersionEntity2111.setVersion("2.1.1.1");
    repoVersionDao.create(repoVersionEntity2111);

    repoVersionEntity2112 = new RepositoryVersionEntity();
    repoVersionEntity2112.setDisplayName("My New Version 3 for patch upgrade");
    repoVersionEntity2112.addRepoOsEntities(createTestOperatingSystems());
    repoVersionEntity2112.setStack(stackEntity211);
    repoVersionEntity2112.setVersion("2.1.1.2");
    repoVersionEntity2112.setType(RepositoryType.PATCH);
    repoVersionEntity2112.setVersionXml("");
    repoVersionDao.create(repoVersionEntity2112);

    repoVersionEntity2200 = new RepositoryVersionEntity();
    repoVersionEntity2200.setDisplayName("My New Version 4 for major upgrade");
    repoVersionEntity2200.addRepoOsEntities(createTestOperatingSystems());
    repoVersionEntity2200.setStack(stackEntity220);
    repoVersionEntity2200.setVersion("2.2.0.0");
    repoVersionDao.create(repoVersionEntity2200);

    clusters = injector.getInstance(Clusters.class);

    clusters.addCluster("c1", stack211);
    cluster = clusters.getCluster("c1");

    clusters.addHost("h1");
    Host host = clusters.getHost("h1");
    Map<String, String> hostAttributes = new HashMap<>();
    hostAttributes.put("os_family", "redhat");
    hostAttributes.put("os_release_version", "6.3");
    host.setHostAttributes(hostAttributes);
    host.setState(HostState.HEALTHY);

    clusters.mapHostToCluster("h1", "c1");

    // add a single ZK server and client on 2.1.1.0
    Service service = cluster.addService("ZOOKEEPER", repoVersionEntity2110);
    ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER");
    ServiceComponentHost sch = component.addServiceComponentHost("h1");
    sch.setVersion("2.1.1.0");

    component = service.addServiceComponent("ZOOKEEPER_CLIENT");
    sch = component.addServiceComponentHost("h1");
    sch.setVersion("2.1.1.0");

    Configuration configuration = injector.getInstance(Configuration.class);
    configuration.setProperty("upgrade.parameter.zk-server.timeout", "824");

    topologyManager = injector.getInstance(TopologyManager.class);
    StageUtils.setTopologyManager(topologyManager);
    StageUtils.setConfiguration(configuration);
    ActionManager.setTopologyManager(topologyManager);
    EasyMock.replay(injector.getInstance(AuditLogger.class));
  }
Creates a single host cluster with ZOOKEEPER_SERVER and ZOOKEEPER_CLIENT on
{@link #repoVersionEntity2110}.

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