@Test
public void testPerform() throws Exception {

  final HostsRepositoryVersionCheck hostsRepositoryVersionCheck = new HostsRepositoryVersionCheck();
  hostsRepositoryVersionCheck.clustersProvider = new Provider<Clusters>() {
    @Override
    public Clusters get() {
      return clusters;
    }
  };
  hostsRepositoryVersionCheck.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
    @Override
    public RepositoryVersionDAO get() {
      return repositoryVersionDAO;
    }
  };
  hostsRepositoryVersionCheck.hostVersionDaoProvider = new Provider<HostVersionDAO>() {
    @Override
    public HostVersionDAO get() {
      return hostVersionDAO;
    }
  };
  final Cluster cluster = Mockito.mock(Cluster.class);
  Mockito.when(cluster.getClusterId()).thenReturn(1L);
  Mockito.when(cluster.getDesiredStackVersion()).thenReturn(new StackId());
  Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
  final Map<String, Host> hosts = new HashMap<String, Host>();
  final Host host1 = Mockito.mock(Host.class);
  final Host host2 = Mockito.mock(Host.class);
  final Host host3 = Mockito.mock(Host.class);
  Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  hosts.put("host1", host1);
  hosts.put("host2", host2);
  hosts.put("host3", host3);
  Mockito.when(clusters.getHostsForCluster("cluster")).thenReturn(hosts);
  Mockito.when(
      repositoryVersionDAO.findByStackAndVersion(Mockito.any(StackId.class),
          Mockito.anyString())).thenReturn(null);
  Mockito.when(
      repositoryVersionDAO.findByStackAndVersion(
          Mockito.any(StackEntity.class), Mockito.anyString())).thenReturn(
      null);
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  hostsRepositoryVersionCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
  StackEntity stackEntity = new StackEntity();
  stackEntity.setStackName("HDP");
  stackEntity.setStackVersion("2.0.6");
  final RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity();
  repositoryVersion.setStack(stackEntity);
  Mockito.when(
      repositoryVersionDAO.findByStackAndVersion(Mockito.any(StackId.class),
          Mockito.anyString())).thenReturn(repositoryVersion);
  Mockito.when(
      repositoryVersionDAO.findByStackAndVersion(
          Mockito.any(StackEntity.class), Mockito.anyString())).thenReturn(
      repositoryVersion);
  final HostVersionEntity hostVersion = new HostVersionEntity();
  hostVersion.setState(RepositoryVersionState.INSTALLED);
  Mockito.when(
      hostVersionDAO.findByClusterStackVersionAndHost(Mockito.anyString(),
          Mockito.any(StackId.class), Mockito.anyString(),
          Mockito.anyString())).thenReturn(hostVersion);
  check = new PrerequisiteCheck(null, null);
  hostsRepositoryVersionCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
}