@Test
public void testUpdateFalconConfigs() throws Exception{

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(
          AmbariManagementController.class);
  final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class);
  final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
  final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
  final Config mockFalconEnv = easyMockSupport.createNiceMock(Config.class);
  final Map<String, String> propertiesExpectedFalconEnv = new HashMap<String, String>();
  propertiesExpectedFalconEnv.put("falcon_store_uri", "file:///hadoop/falcon/store");
  propertiesExpectedFalconEnv.put("content", "# content");
  propertiesExpectedFalconEnv.put("property", "value");
  final String applicationServicesOldPropertyValue =
      "org.apache.falcon.security.AuthenticationInitializationService,\\\n" +
      "      org.apache.falcon.workflow.WorkflowJobEndNotificationService, \\\n" +
      "      org.apache.falcon.service.ProcessSubscriberService,\\\n" +
      "      org.apache.falcon.entity.store.ConfigurationStore,\\\n" +
      "      org.apache.falcon.rerun.service.RetryService,\\\n" +
      "      org.apache.falcon.rerun.service.LateRunService,\\\n" +
      "      org.apache.falcon.service.LogCleanupService,\\\n" +
      "      org.apache.falcon.metadata.MetadataMappingService";
  final String applicationServicesExpectedPropertyValue =
      "org.apache.falcon.security.AuthenticationInitializationService,\\\n" +
      "      org.apache.falcon.workflow.WorkflowJobEndNotificationService, \\\n" +
      "      org.apache.falcon.service.ProcessSubscriberService,\\\n" +
      "      org.apache.falcon.entity.store.ConfigurationStore,\\\n" +
      "      org.apache.falcon.rerun.service.RetryService,\\\n" +
      "      org.apache.falcon.rerun.service.LateRunService,\\\n" +
      "      org.apache.falcon.service.LogCleanupService,\\\n" +
      "      org.apache.falcon.metadata.MetadataMappingService{{atlas_application_class_addition}}";
  final Config falconStartupConfig = easyMockSupport.createNiceMock(Config.class);
  final Map<String, String> falconStartupConfigProperties= new HashMap<String, String>();
  falconStartupConfigProperties.put("*.application.services", applicationServicesOldPropertyValue);
  falconStartupConfigProperties.put("property", "value");
  final Injector mockInjector = Guice.createInjector(new Module() {
    @Override
    public void configure(Binder binder) {
      binder.bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
      binder.bind(ConfigHelper.class).toInstance(mockConfigHelper);
      binder.bind(Clusters.class).toInstance(mockClusters);
      binder.bind(EntityManager.class).toInstance(entityManager);
      binder.bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
      binder.bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class));
      binder.bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class));
      binder.bind(HookService.class).toInstance(createMock(HookService.class));
    }
  });
  expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
  expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
    put("normal", mockClusterExpected);
  }}).once();
  expect(mockClusterExpected.getDesiredConfigByType("falcon-env")).andReturn(mockFalconEnv).atLeastOnce();
  expect(mockFalconEnv.getProperties()).andReturn(propertiesExpectedFalconEnv).anyTimes();
  expect(mockClusterExpected.getDesiredConfigByType("falcon-startup.properties")).andReturn(falconStartupConfig).atLeastOnce();
  expect(falconStartupConfig.getProperties()).andReturn(falconStartupConfigProperties).anyTimes();
  Capture<Map<String, String>> falconCapture =  newCapture();
  expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"),
      capture(falconCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
  Capture<Map<String, String>> falconCapture2 =  newCapture();
  expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"),
      capture(falconCapture2), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
  Capture<Map<String, String>> falconStartupCapture =  newCapture();
  expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-startup.properties"),
      capture(falconStartupCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
  easyMockSupport.replayAll();
  mockInjector.getInstance(UpgradeCatalog240.class).updateFalconConfigs();
  easyMockSupport.verifyAll();
  final String expectredEnvContent = "# content\n" +
                                     "\n" +
                                     "{% if falcon_atlas_support %}\n" +
                                     "# Add the Atlas Falcon hook to the Falcon classpath\n" +
                                     "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" +
                                     "{% endif %}";
  assertEquals("value", falconCapture.getValue().get("property"));
  assertEquals("# content", falconCapture.getValue().get("content"));
  assertNull(falconCapture.getValue().get("falcon_store_uri"));
  assertEquals(expectredEnvContent, falconCapture2.getValue().get("content"));
  assertEquals("value", falconStartupCapture.getValue().get("property"));
  assertEquals(applicationServicesExpectedPropertyValue, falconStartupCapture.getValue().get("*.application.services"));
}