DirectHeaderExtractor { public SoapEdgeContext getHeaderProperties(WebServiceContext context) { if (context == null) { throw new DirectException("WebServiceContext was null."); } MessageContext msgContext = context.getMessageContext(); SoapEdgeContext headers = getHeaderProperties(msgContext); ServletRequest sr = (ServletRequest) msgContext.get(MessageContext.SERVLET_REQUEST); if (sr != null) { headers.setRemoteHost(sr.getRemoteHost()); headers.setThisHost(sr.getServerName()); } return headers; }  SoapEdgeContext getHeaderProperties(WebServiceContext context);  }
@Test(expected = DirectException.class) public void testGetHeaderProperties_WebServiceContextNull() { WebServiceContext context = null; new DirectHeaderExtractor().getHeaderProperties(context); }
@Test(expected = DirectException.class) public void testGetHeaderProperties_MessageContextNull() { WebServiceContext context = mock(WebServiceContext.class); when(context.getMessageContext()).thenReturn(null); new DirectHeaderExtractor().getHeaderProperties(context); }
@Test(expected = DirectException.class) public void testGetHeaderProperties_ContentNull() { WebServiceContext context = mock(WebServiceContext.class); Message msg = mock(Message.class); WrappedMessageContext messageContext = new WrappedMessageContext(msg); when(context.getMessageContext()).thenReturn(messageContext); new DirectHeaderExtractor().getHeaderProperties(context); }
@Test(expected = DirectException.class) public void testGetHeaderProperties_EnvelopeNull() { WebServiceContext context = mock(WebServiceContext.class); Message msg = mock(Message.class); Node content = mock(Node.class); NodeListImpl contentChildren = new NodeListImpl(); WrappedMessageContext messageContext = new WrappedMessageContext(msg); when(context.getMessageContext()).thenReturn(messageContext); when(msg.getContent(Node.class)).thenReturn(content); when(content.getChildNodes()).thenReturn(contentChildren); new DirectHeaderExtractor().getHeaderProperties(context); }
@Test public void testGetHeaderProperties() { WebServiceContext context = mock(WebServiceContext.class); Message msg = mock(Message.class); WrappedMessageContext messageContext = new WrappedMessageContext(msg); when(context.getMessageContext()).thenReturn(messageContext); Node content = mock(Node.class); NodeListImpl envelope = new NodeListImpl(); Node envNode = mock(Node.class); envelope.add(envNode); NodeListImpl header = new NodeListImpl(); Node headerNode = mock(Node.class); header.add(headerNode); when(msg.getContent(Node.class)).thenReturn(content); when(content.getChildNodes()).thenReturn(envelope); when(envNode.getNodeName()).thenReturn("Envelope"); when(envNode.getChildNodes()).thenReturn(header); when(headerNode.getNodeName()).thenReturn("Header"); when(headerNode.getChildNodes()).thenReturn(getHeaderNodeList()); ServletRequest request = mock(ServletRequest.class); when(messageContext.get(MessageContext.SERVLET_REQUEST)).thenReturn(request); when(request.getRemoteHost()).thenReturn(REMOTE_HOST); when(request.getServerName()).thenReturn(SERVER_NAME); DirectHeaderExtractor extractor = new DirectHeaderExtractor(); SoapEdgeContext edgeContext = extractor.getHeaderProperties(context); checkEdgeContext(edgeContext); }