### Question:
RangerUsersyncConfigCalculation extends AbstractUpgradeServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = getClusters().getCluster(clusterName); String outputMsg = ""; Config rangerUsersyncConfig = cluster.getDesiredConfigByType(RANGER_USERSYNC_CONFIG_TYPE); if (null == rangerUsersyncConfig) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping updating property in same.", RANGER_USERSYNC_CONFIG_TYPE), ""); } String ldapGroupHierarchy = "0"; if (rangerUsersyncConfig.getProperties().containsKey("ranger.usersync.ldap.grouphierarchylevels")) { ldapGroupHierarchy = rangerUsersyncConfig.getProperties().get("ranger.usersync.ldap.grouphierarchylevels"); } else { Map<String, String> targetRangerUsersyncConfig = rangerUsersyncConfig.getProperties(); targetRangerUsersyncConfig.put("ranger.usersync.ldap.grouphierarchylevels", ldapGroupHierarchy); rangerUsersyncConfig.setProperties(targetRangerUsersyncConfig); rangerUsersyncConfig.save(); outputMsg = outputMsg + MessageFormat.format("Successfully updated {0} config type.\n", RANGER_USERSYNC_CONFIG_TYPE); } Config rangerEnvConfig = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnvConfig) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping updating property in same.", RANGER_ENV_CONFIG_TYPE), ""); } String enableSyncNestedGroup = "false"; if (!ldapGroupHierarchy.equals("0") ) { enableSyncNestedGroup = "true"; } Map<String, String> targetRangerEnvConfig = rangerEnvConfig.getProperties(); targetRangerEnvConfig.put("is_nested_groupsync_enabled", enableSyncNestedGroup); rangerEnvConfig.setProperties(targetRangerEnvConfig); rangerEnvConfig.save(); agentConfigsHolder.updateData(cluster.getClusterId(), cluster.getHosts().stream().map(Host::getHostId).collect(Collectors.toList())); outputMsg = outputMsg + MessageFormat.format("Successfully updated {0} config type.\n", RANGER_ENV_CONFIG_TYPE); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }### Answer:
@Test public void testAction() throws Exception { Map<String, String> commandParams = new HashMap<String, String>(); commandParams.put("clusterName", "cl1"); ExecutionCommand executionCommand = new ExecutionCommand(); executionCommand.setCommandParams(commandParams); executionCommand.setClusterName("cl1"); HostRoleCommand hrc = createMock(HostRoleCommand.class); expect(hrc.getRequestId()).andReturn(1L).anyTimes(); expect(hrc.getStageId()).andReturn(2L).anyTimes(); expect(hrc.getExecutionCommandWrapper()).andReturn(new ExecutionCommandWrapper(executionCommand)).anyTimes(); replay(hrc); RangerUsersyncConfigCalculation action = new RangerUsersyncConfigCalculation(); m_clusterField.set(action, m_clusters); agentConfigsHolderField.set(action, agentConfigsHolder); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hrc); CommandReport report = action.execute(null); Assert.assertNotNull(report); Cluster cl = m_clusters.getCluster("cl1"); Config config = cl.getDesiredConfigByType("ranger-env"); Map<String, String> map = config.getProperties(); Assert.assertTrue(map.containsKey("is_nested_groupsync_enabled")); Assert.assertEquals("true", map.get("is_nested_groupsync_enabled")); report = action.execute(null); Assert.assertNotNull(report); }