@Test
public void testUpgradeCapSchedulerView() throws SQLException, MaskException {

  final RemoteAmbariClusterDAO clusterDAO = createNiceMock(RemoteAmbariClusterDAO.class);
  final ViewInstanceDAO instanceDAO = createNiceMock(ViewInstanceDAO.class);
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
      bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
      bind(RemoteAmbariClusterDAO.class).toInstance(clusterDAO);
      bind(ViewInstanceDAO.class).toInstance(instanceDAO);
      bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class));
      bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class));
      bind(HookService.class).toInstance(createMock(HookService.class));
    }
  });
  List<ViewInstanceEntity> instances = new ArrayList<ViewInstanceEntity>();
  ViewInstanceEntity instance1 = createNiceMock(ViewInstanceEntity.class);
  expect(instance1.getViewName()).andReturn("CAPACITY-SCHEDULER{1.0.0}");
  expect(instance1.getClusterHandle()).andReturn(null);
  instances.add(instance1);
  Map<String,String> propertyMap = new HashMap<String,String>();
  String url = "url";
  String username = "user";
  String password = "password";
  propertyMap.put("ambari.server.url",url);
  propertyMap.put("ambari.server.username",username);
  propertyMap.put("ambari.server.password",new DefaultMasker().mask(password));
  expect(instance1.getPropertyMap()).andReturn(propertyMap);
  expect(instance1.getName()).andReturn("instance");
  expect(instanceDAO.findAll()).andReturn(instances);
  Capture<RemoteAmbariClusterEntity> clusterEntityCapture = newCapture();
  clusterDAO.save(capture(clusterEntityCapture));
  instance1.setClusterType(ClusterType.REMOTE_AMBARI);
  instance1.setClusterHandle(null);
  expect(instanceDAO.merge(eq(instance1))).andReturn(instance1);
  replay(clusterDAO, instanceDAO, instance1);
  mockInjector.getInstance(UpgradeCatalog240.class).upgradeCapSchedulerView();
  assertEquals("instance-cluster", clusterEntityCapture.getValue().getName());
  assertEquals(url, clusterEntityCapture.getValue().getUrl());
  assertEquals(username, clusterEntityCapture.getValue().getUsername());
  assertEquals(password, clusterEntityCapture.getValue().getPassword());
  verify(clusterDAO, instanceDAO, instance1);
}