UpgradeCatalog2121 extends AbstractUpgradeCatalog { protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values()) { Config oozieSiteProps = cluster.getDesiredConfigByType(OOZIE_SITE_CONFIG); if (oozieSiteProps != null) { String oozieAuthKerbRules = oozieSiteProps.getProperties().get(OOZIE_AUTHENTICATION_KERBEROS_NAME_RULES); if (StringUtils.isBlank(oozieAuthKerbRules)) { Set<String> removeProperties = new HashSet<String>(); removeProperties.add(OOZIE_AUTHENTICATION_KERBEROS_NAME_RULES); updateConfigurationPropertiesForCluster(cluster, OOZIE_SITE_CONFIG, new HashMap<String, String>(), removeProperties, true, false); } } } } @Inject  UpgradeCatalog2121(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testUpdateOozieConfigs() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final Map<String, String> propertiesOozieSite = new HashMap<String, String>() {{ put("oozie.authentication.kerberos.name.rules", "\n "); }}; final Config oozieSiteConf = easyMockSupport.createNiceMock(Config.class); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(Clusters.class).toInstance(mockClusters); bind(EntityManager.class).toInstance(entityManager); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("oozie-site")).andReturn(oozieSiteConf).atLeastOnce(); expect(oozieSiteConf.getProperties()).andReturn(propertiesOozieSite).once(); UpgradeCatalog2121 upgradeCatalog2121 = createMockBuilder(UpgradeCatalog2121.class) .withConstructor(Injector.class) .withArgs(mockInjector) .addMockedMethod("updateConfigurationPropertiesForCluster", Cluster.class, String.class, Map.class, Set.class, boolean.class, boolean.class) .createMock(); upgradeCatalog2121.updateConfigurationPropertiesForCluster(mockClusterExpected, "oozie-site", new HashMap<String, String>(), Collections.singleton("oozie.authentication.kerberos.name.rules"), true, false); expectLastCall().once(); easyMockSupport.replayAll(); replay(upgradeCatalog2121); upgradeCatalog2121.updateOozieConfigs(); easyMockSupport.verifyAll(); }