### Question:
EchoEndpoint { @PayloadRoot(localPart = ECHO_REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI) @ResponsePayload public Element handleEchoRequest(@RequestPayload Element requestElement) throws ParserConfigurationException { Assert.isTrue(NAMESPACE_URI.equals(requestElement.getNamespaceURI()), "Invalid namespace"); Assert.isTrue(ECHO_REQUEST_LOCAL_NAME.equals(requestElement.getLocalName()), "Invalid local name"); NodeList children = requestElement.getChildNodes(); Text requestText = null; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.TEXT_NODE) { requestText = (Text) children.item(i); break; } } if (requestText == null) { throw new IllegalArgumentException("Could not find request text node"); } String echo = echoService.echo(requestText.getNodeValue()); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element responseElement = document.createElementNS(NAMESPACE_URI, ECHO_RESPONSE_LOCAL_NAME); Text responseText = document.createTextNode(echo); responseElement.appendChild(responseText); return responseElement; } EchoEndpoint(EchoService echoService); @PayloadRoot(localPart = ECHO_REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI) @ResponsePayload Element handleEchoRequest(@RequestPayload Element requestElement); static final String NAMESPACE_URI; static final String ECHO_REQUEST_LOCAL_NAME; static final String ECHO_RESPONSE_LOCAL_NAME; }### Answer:
@Test public void testInvokeInternal() throws Exception { Element echoRequest = requestDocument.createElementNS(EchoEndpoint.NAMESPACE_URI, EchoEndpoint.ECHO_REQUEST_LOCAL_NAME); Text requestText = requestDocument.createTextNode("ABC"); echoRequest.appendChild(requestText); when(echoServiceMock.echo("ABC")).thenReturn("DEF"); Element echoResponse = endpoint.handleEchoRequest(echoRequest); assertThat(echoResponse.getNamespaceURI()).isEqualTo(EchoEndpoint.NAMESPACE_URI); assertThat(echoResponse.getLocalName()).isEqualTo(EchoEndpoint.ECHO_RESPONSE_LOCAL_NAME); assertThat(echoResponse.getChildNodes().item(0).getNodeValue()).isEqualTo("DEF"); verify(echoServiceMock); }