### Question:
SoapHeaderTransport { public Map<String, String> parseSoapHeader(final Element soapHeader) { final NodeList tpicHeaders = soapHeader.getElementsByTagNameNS(TraceeConstants.SOAP_HEADER_NAMESPACE, TraceeConstants.TPIC_HEADER); final HashMap<String, String> contextMap = new HashMap<>(); if (tpicHeaders != null && tpicHeaders.getLength() > 0) { final int items = tpicHeaders.getLength(); for (int i = 0; i < items; i++) { contextMap.putAll(parseTpicHeader((Element) tpicHeaders.item(i))); } } return contextMap; } SoapHeaderTransport(); Map<String, String> parseSoapHeader(final Element soapHeader); Map<String, String> parseTpicHeader(final Element element); Map<String, String> parseTpicHeader(final Source source); void renderSoapHeader(final Map<String, String> context, final SOAPHeader soapHeader); void renderSoapHeader(final Map<String, String> context, final Result result);  }### Answer:
@Test public void parseSoapHeaderWithOneTPICHeader() throws SOAPException, JAXBException { final TpicMap tpicMap = TpicMap.wrap(Collections.singletonMap("FOooo", "Bar2")); JAXBContext.newInstance(TpicMap.class).createMarshaller().marshal(tpicMap, soapMessage.getSOAPHeader()); final Map<String, String> parse = unit.parseSoapHeader(soapMessage.getSOAPHeader()); assertThat(parse, hasEntry("FOooo", "Bar2")); }
@Test public void parseSoapHeaderWithMultipleTPICHeader() throws SOAPException, JAXBException { final TpicMap tpicMap = TpicMap.wrap(Collections.singletonMap("FOooo", "Bar2")); final TpicMap tpicMap2 = TpicMap.wrap(Collections.singletonMap("FOooo2", "Bar3")); JAXBContext.newInstance(TpicMap.class).createMarshaller().marshal(tpicMap, soapMessage.getSOAPHeader()); JAXBContext.newInstance(TpicMap.class).createMarshaller().marshal(tpicMap2, soapMessage.getSOAPHeader()); final Map<String, String> parse = unit.parseSoapHeader(soapMessage.getSOAPHeader()); assertThat(parse, hasEntry("FOooo", "Bar2")); assertThat(parse, hasEntry("FOooo2", "Bar3")); }
@Test public void parseSoapHeaderToEmptyMapIfNotParsable() throws SOAPException { assertThat(unit.parseSoapHeader(soapMessage.getSOAPHeader()), equalTo(Collections.<String, String>emptyMap())); }
@Test public void readRealXmlMessageAndParseHeader() throws ParserConfigurationException, IOException, SAXException { final InputStream xmlDoc = ClassLoader.getSystemResourceAsStream("io/tracee/transport/jaxws-output.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); Document doc = dbFactory.newDocumentBuilder().parse(xmlDoc); Element envelope = (Element) doc.getElementsByTagNameNS("http: Element header = (Element) envelope.getElementsByTagNameNS("http: Map<String, String> parsedContextParams = unit.parseSoapHeader(header); assertThat(parsedContextParams, hasEntry(TraceeConstants.INVOCATION_ID_KEY, "ANU0N88T6YASTEVHN9VK0HJ75SXB87ZQ")); }