@Test
public void testPersistHDPRepo() throws Exception {

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  final AmbariManagementController  mockAmbariManagementController = easyMockSupport.createStrictMock(AmbariManagementController.class);
  final AmbariMetaInfo mockAmbariMetaInfo = easyMockSupport.createNiceMock(AmbariMetaInfo.class);
  final StackInfo mockStackInfo = easyMockSupport.createNiceMock(StackInfo.class);
  final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
  final Cluster mockCluster = easyMockSupport.createStrictMock(Cluster.class);
  final Map<String, Cluster> clusterMap = new HashMap<String, Cluster>();
  clusterMap.put("c1",mockCluster);
  OperatingSystemInfo osi = new OperatingSystemInfo("redhat6");
  HashSet<OperatingSystemInfo> osiSet = new HashSet<OperatingSystemInfo>();
  osiSet.add(osi);
  StackId stackId = new StackId("HDP","2.2");
  final RepositoryInfo mockRepositoryInfo = easyMockSupport.createNiceMock(RepositoryInfo.class);
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
      bind(Clusters.class).toInstance(mockClusters);
      bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
      bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
    }
  });
  expect(mockAmbariManagementController.getAmbariMetaInfo()).andReturn(mockAmbariMetaInfo);
  expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
  expect(mockClusters.getClusters()).andReturn(clusterMap).once();
  expect(mockCluster.getCurrentStackVersion()).andReturn(stackId).once();
  expect(mockCluster.getClusterName()).andReturn("cc").anyTimes();
  expect(mockAmbariMetaInfo.getOperatingSystems("HDP", "2.2")).andReturn(osiSet).once();
  expect(mockAmbariMetaInfo.getRepository("HDP", "2.2", "redhat6", "HDP-2.2")).andReturn(mockRepositoryInfo).once();
  expect(mockAmbariMetaInfo.getStack("HDP", "2.2")).andReturn(mockStackInfo);
  expect(mockStackInfo.getRepositories()).andReturn(new ArrayList<RepositoryInfo>() {{
    add(mockRepositoryInfo);
  }});
  expect(mockRepositoryInfo.getDefaultBaseUrl()).andReturn("http://baseurl").once();
  mockAmbariMetaInfo.updateRepo("HDP", "2.2", "redhat6", "HDP-2.2", "http://baseurl", null);
  expectLastCall().once();
  easyMockSupport.replayAll();
  mockInjector.getInstance(UpgradeCatalog200.class).persistHDPRepo();
  easyMockSupport.verifyAll();
}