@Before
  public void setup() throws Exception {
    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
    // Use the same cache provider to ensure there is only once instance of
    // Cache available. The @org.ehcache.CacheManager is a singleton and
    // does not allow multiple instance with same cache name to be registered.
    injector = Guice.createInjector(Modules.override(module).with(new TestModuleWithCacheProvider()));
    injector.getInstance(GuiceJpaInitializer.class);
    StackDefinedPropertyProvider.init(injector);

    metricsRetrievalService = injector.getInstance(
        MetricsRetrievalService.class);

    metricsRetrievalService.startAsync();
    metricsRetrievalService.awaitRunning(METRICS_SERVICE_TIMEOUT, TimeUnit.SECONDS);
    metricsRetrievalService.setThreadPoolExecutor(new SynchronousThreadPoolExecutor());

    helper = injector.getInstance(OrmTestHelper.class);

    clusters = injector.getInstance(Clusters.class);
    StackId stackId = new StackId("HDP-2.0.5");

    clusters.addCluster("c2", stackId);

    Cluster cluster = clusters.getCluster("c2");

    cluster.setDesiredStackVersion(stackId);
    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
    Service service = cluster.addService("HDFS", repositoryVersion);
    service.addServiceComponent("NAMENODE");
    service.addServiceComponent("DATANODE");
    service.addServiceComponent("JOURNALNODE");

    service = cluster.addService("YARN", repositoryVersion);
    service.addServiceComponent("RESOURCEMANAGER");

    service = cluster.addService("HBASE", repositoryVersion);
    service.addServiceComponent("HBASE_MASTER");
    service.addServiceComponent("HBASE_REGIONSERVER");

    stackId = new StackId("HDP-2.1.1");
    repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());

    service = cluster.addService("STORM", repositoryVersion);
    service.addServiceComponent("STORM_REST_API");

    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);

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

    // Setting up Mocks for Controller, Clusters etc, queried as part of user's Role context
    // while fetching Metrics.
    AmbariManagementController amc = createNiceMock(AmbariManagementController.class);
    Field field = AmbariServer.class.getDeclaredField("clusterController");
    field.setAccessible(true);
    field.set(null, amc);
    Clusters clustersMock = createNiceMock(Clusters.class);
    Cluster clusterMock = createNiceMock(Cluster.class);
    expect(amc.getAmbariEventPublisher()).andReturn(createNiceMock(AmbariEventPublisher.class)).anyTimes();
    expect(amc.getClusters()).andReturn(clustersMock).anyTimes();
    expect(clustersMock.getCluster(CLUSTER_NAME_PROPERTY_ID)).andReturn(clusterMock).anyTimes();
    expect(clusterMock.getResourceId()).andReturn(2L).anyTimes();
    try {
      expect(clustersMock.getCluster(anyObject(String.class))).andReturn(clusterMock).anyTimes();
    } catch (AmbariException e) {
      e.printStackTrace();
    }
    replay(amc, clustersMock, clusterMock);
  }
Tests the stack defined property provider.
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java