@Test
public void testUpdateViewInstance() throws Exception {

  ViewRegistry registry = ViewRegistry.getInstance();
  Properties properties = new Properties();
  properties.put("p1", "v1");
  Configuration ambariConfig = new Configuration(properties);
  ViewConfig config = ViewConfigTest.getConfig(XML_VALID_INSTANCE);
  ViewEntity viewEntity = getViewEntity(config, ambariConfig, getClass().getClassLoader(), "");
  ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
  ViewInstanceEntity updateInstance = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
  expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(viewInstanceEntity);
  expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", viewInstanceEntity.getInstanceName())).andReturn(viewInstanceEntity).anyTimes();
  replay(viewDAO, viewInstanceDAO, securityHelper);
  registry.addDefinition(viewEntity);
  registry.installViewInstance(viewInstanceEntity);
  Assert.assertTrue(viewInstanceEntity.isVisible());
  updateInstance.setLabel("new label");
  updateInstance.setDescription("new description");
  updateInstance.setVisible(false);
  registry.updateViewInstance(updateInstance);
  Collection<ViewInstanceEntity> viewInstanceDefinitions = registry.getInstanceDefinitions(viewEntity);
  Assert.assertEquals(1, viewInstanceDefinitions.size());
  ViewInstanceEntity instanceEntity = viewInstanceDefinitions.iterator().next();
  Assert.assertEquals("v2-1", instanceEntity.getProperty("p2").getValue() );
  Assert.assertEquals("new label", instanceEntity.getLabel() );
  Assert.assertEquals("new description", instanceEntity.getDescription() );
  Assert.assertFalse(instanceEntity.isVisible());
  Assert.assertEquals(viewInstanceEntity, viewInstanceDefinitions.iterator().next());
  verify(viewDAO, viewInstanceDAO, securityHelper);
}