### Question:
HaDescriptorManager implements HaDescriptorConstants { public static void store(HaDescriptor descriptor, Writer writer) throws IOException { try { Document document = XmlUtils.createDocument(); Element root = document.createElement(ROOT_ELEMENT); document.appendChild(root); List<HaServiceConfig> serviceConfigs = descriptor.getServiceConfigs(); if (serviceConfigs != null && !serviceConfigs.isEmpty()) { for (HaServiceConfig config : serviceConfigs) { Element serviceElement = document.createElement(SERVICE_ELEMENT); serviceElement.setAttribute(SERVICE_NAME_ATTRIBUTE, config.getServiceName()); serviceElement.setAttribute(MAX_FAILOVER_ATTEMPTS, Integer.toString(config.getMaxFailoverAttempts())); serviceElement.setAttribute(FAILOVER_SLEEP, Integer.toString(config.getFailoverSleep())); serviceElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(config.isEnabled())); if (config.getZookeeperEnsemble() != null) { serviceElement.setAttribute(ZOOKEEPER_ENSEMBLE, config.getZookeeperEnsemble()); } if (config.getZookeeperNamespace() != null) { serviceElement.setAttribute(ZOOKEEPER_NAMESPACE, config.getZookeeperNamespace()); } root.appendChild(serviceElement); } } Transformer t = XmlUtils.getTransformer( true, true, 2, false ); XmlUtils.writeXml( document, writer, t ); } catch (ParserConfigurationException | TransformerException e) { LOG.failedToWriteHaDescriptor(e); throw new IOException(e); } }  static void store(HaDescriptor descriptor, Writer writer); static HaDescriptor load(InputStream inputStream);  }### Answer:
@Test public void testDescriptorStoring() throws IOException { HaDescriptor descriptor = HaDescriptorFactory.createDescriptor(); descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig("foo", "false", "42", "1000", "foo:2181,bar:2181", "hiveserver2")); descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig("bar", "true", "3", "5000", null, null)); StringWriter writer = new StringWriter(); HaDescriptorManager.store(descriptor, writer); String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<ha>\n" + " <service enabled=\"false\" failoverSleep=\"1000\" maxFailoverAttempts=\"42\" name=\"foo\" zookeeperEnsemble=\"foo:2181,bar:2181\" zookeeperNamespace=\"hiveserver2\"/>\n" + " <service enabled=\"true\" failoverSleep=\"5000\" maxFailoverAttempts=\"3\" name=\"bar\"/>\n" + "</ha>\n"; assertThat( the( xml ), hasXPath( "/ha/service[@enabled='false' and @failoverSleep='1000' and @maxFailoverAttempts='42' and @name='foo' and @zookeeperEnsemble='foo:2181,bar:2181' and @zookeeperNamespace='hiveserver2']" ) ); assertThat( the( xml ), hasXPath( "/ha/service[@enabled='true' and @failoverSleep='5000' and @maxFailoverAttempts='3' and @name='bar']" ) ); }