### Question:
HaDescriptorManager implements HaDescriptorConstants { public static HaDescriptor load(InputStream inputStream) throws IOException { HaDescriptor descriptor = HaDescriptorFactory.createDescriptor(); try { Document document = XmlUtils.readXml( inputStream ); NodeList nodeList = document.getElementsByTagName(SERVICE_ELEMENT); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); HaServiceConfig config = HaDescriptorFactory.createServiceConfig(element.getAttribute(SERVICE_NAME_ATTRIBUTE), element.getAttribute(ENABLED_ATTRIBUTE), element.getAttribute(MAX_FAILOVER_ATTEMPTS), element.getAttribute(FAILOVER_SLEEP), element.getAttribute(ZOOKEEPER_ENSEMBLE), element.getAttribute(ZOOKEEPER_NAMESPACE)); descriptor.addServiceConfig(config); } } } catch (ParserConfigurationException | SAXException e) { LOG.failedToLoadHaDescriptor(e); throw new IOException(e); } return descriptor; }  static void store(HaDescriptor descriptor, Writer writer); static HaDescriptor load(InputStream inputStream);  }### Answer:
@Test public void testDescriptorLoad() throws IOException { String xml = "<ha><service name='foo' maxFailoverAttempts='42' failoverSleep='4000' enabled='false'/>" + "<service name='bar' failoverLimit='3' enabled='true'/></ha>"; ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); HaDescriptor descriptor = HaDescriptorManager.load(inputStream); assertNotNull(descriptor); assertEquals(1, descriptor.getEnabledServiceNames().size()); HaServiceConfig config = descriptor.getServiceConfig("foo"); assertNotNull(config); assertEquals("foo", config.getServiceName()); assertEquals(42, config.getMaxFailoverAttempts()); assertEquals(4000, config.getFailoverSleep()); assertFalse(config.isEnabled()); config = descriptor.getServiceConfig("bar"); assertTrue(config.isEnabled()); }
@Test public void testDescriptorDefaults() throws IOException { String xml = "<ha><service name='foo'/></ha>"; ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); HaDescriptor descriptor = HaDescriptorManager.load(inputStream); assertNotNull(descriptor); assertEquals(1, descriptor.getEnabledServiceNames().size()); HaServiceConfig config = descriptor.getServiceConfig("foo"); assertNotNull(config); assertEquals("foo", config.getServiceName()); assertEquals(HaServiceConfigConstants.DEFAULT_MAX_FAILOVER_ATTEMPTS, config.getMaxFailoverAttempts()); assertEquals(HaServiceConfigConstants.DEFAULT_FAILOVER_SLEEP, config.getFailoverSleep()); assertEquals(HaServiceConfigConstants.DEFAULT_ENABLED, config.isEnabled()); }