List of usage examples for javax.xml.soap SOAPBody addBodyElement
public SOAPBodyElement addBodyElement(QName qname) throws SOAPException;
From source file:unit.test.be.e_contract.mycarenet.ehealth.common.WSSecuritySOAPHandlerTest.java
@Test public void testHandleMessage() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); KeyPair keyPair = keyPairGenerator.generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); String samlAssertion = "<Assertion xmlns=\"urn:oasis:names:tc:SAML:1.0:assertion\"" + " AssertionID=\"_42e7a00652420d86ee884f295a3fbf02\">" + "</Assertion>"; WSSecuritySOAPHandler testedInstance = new WSSecuritySOAPHandler(); testedInstance.setPrivateKey(privateKey); testedInstance.setAssertion(samlAssertion); SOAPMessageContext mockSoapMessageContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockSoapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).andReturn(true); MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); soapBody.addBodyElement(new QName("http://www.example.com", "Test")); EasyMock.expect(mockSoapMessageContext.getMessage()).andReturn(soapMessage); // prepare//from w w w .java 2 s .co m EasyMock.replay(mockSoapMessageContext); // operate testedInstance.handleMessage(mockSoapMessageContext); // verify EasyMock.verify(mockSoapMessageContext); LOG.debug(toString(soapPart)); }