### Question:
HadoopXmlResourceParser implements AdvancedServiceDiscoveryConfigChangeListener { public HadoopXmlResourceParserResult parse(String path) { return parse(path, null); } HadoopXmlResourceParser(GatewayConfig gatewayConfig); HadoopXmlResourceParserResult parse(String path); HadoopXmlResourceParserResult parse(String path, String topologyName); @Override void onAdvancedServiceDiscoveryConfigurationChange(Properties newConfiguration);  }### Answer:
@Test public void testCMDescriptorParser() throws Exception { final String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptor.xml").getPath(); final HadoopXmlResourceParserResult parserResult = hadoopXmlResourceParser.parse(testConfigPath); final Set<SimpleDescriptor> descriptors = parserResult.getDescriptors(); assertEquals(2, descriptors.size()); final Iterator<SimpleDescriptor> descriptorsIterator = descriptors.iterator(); validateTopology1Descriptors(descriptorsIterator.next()); validateTopology2Descriptors(descriptorsIterator.next(), true); validateTestDescriptorProviderConfigs(parserResult.getProviders(), "ldap: }
@Test public void testCMDescriptorParserOnlyTopology2() throws Exception { final String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptor.xml").getPath(); final Set<SimpleDescriptor> descriptors = hadoopXmlResourceParser.parse(testConfigPath, "topology2").getDescriptors(); assertEquals(1, descriptors.size()); validateTopology2Descriptors(descriptors.iterator().next(), true); }
@Test public void testCMDescriptorParserWrongDescriptorContent() throws Exception { final String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptorConfigurationWithWrongDescriptor.xml").getPath(); final Set<SimpleDescriptor> descriptors = hadoopXmlResourceParser.parse(testConfigPath).getDescriptors(); assertEquals(1, descriptors.size()); final Iterator<SimpleDescriptor> descriptorsIterator = descriptors.iterator(); validateTopology1Descriptors(descriptorsIterator.next()); }
@Test public void testCMDescriptorParserWrongXMLContent() throws Exception { final String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptorConfigurationWithNonHadoopStyleConfiguration.xml").getPath(); final Set<SimpleDescriptor> descriptors = hadoopXmlResourceParser.parse(testConfigPath).getDescriptors(); assertTrue(descriptors.isEmpty()); }
@Test public void testCMDescriptorParserModifyingProviderParams() { String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptor.xml").getPath(); HadoopXmlResourceParserResult parserResult = hadoopXmlResourceParser.parse(testConfigPath); validateTestDescriptorProviderConfigs(parserResult.getProviders(), "ldap: parserResult.getProviders().forEach((key, value) -> { final File knoxProviderConfigFile = new File(providersDir, key + ".json"); final String providersConfiguration = JsonUtils.renderAsJsonString(value); try { FileUtils.writeStringToFile(knoxProviderConfigFile, providersConfiguration, StandardCharsets.UTF_8); } catch (IOException e) { fail("Could not save " + knoxProviderConfigFile.getAbsolutePath()); } }); testConfigPath = this.getClass().getClassLoader().getResource("testDescriptorWithAdminProviderConfigUpdatedLdapUrl.xml").getPath(); parserResult = hadoopXmlResourceParser.parse(testConfigPath); validateTestDescriptorProviderConfigs(parserResult.getProviders(), "ldaps: }
@Test public void testCMDescriptorParserRemovingProviderParams() { String testConfigPath = this.getClass().getClassLoader().getResource("testDescriptor.xml").getPath(); HadoopXmlResourceParserResult parserResult = hadoopXmlResourceParser.parse(testConfigPath); parserResult.getProviders().forEach((key, value) -> { final File knoxProviderConfigFile = new File(providersDir, key + ".json"); final String providersConfiguration = JsonUtils.renderAsJsonString(value); try { FileUtils.writeStringToFile(knoxProviderConfigFile, providersConfiguration, StandardCharsets.UTF_8); } catch (IOException e) { fail("Could not save " + knoxProviderConfigFile.getAbsolutePath()); } }); testConfigPath = this.getClass().getClassLoader().getResource("testDescriptorWithAdminProviderConfigRemovedUserDnTemplate.xml").getPath(); parserResult = hadoopXmlResourceParser.parse(testConfigPath); validateTestDescriptorProviderConfigs(parserResult.getProviders(), "ldap: }