1 17 18 package org.apache.sandesha.server; 19 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.handlers.soap.SOAPService; 23 import org.apache.axis.message.addressing.AddressingHeaders; 24 import org.apache.sandesha.AbstractTestCase; 25 import org.apache.sandesha.Constants; 26 import org.apache.sandesha.RMMessageContext; 27 import org.apache.sandesha.ws.rm.providers.RMProvider; 28 29 import javax.xml.soap.SOAPBody ; 30 import javax.xml.soap.SOAPFault ; 31 32 33 public class TCMessageValidator extends AbstractTestCase { 34 37 public TCMessageValidator(String testName) { 38 super(testName); 39 } 40 41 protected void setUp() throws Exception { 42 43 } 44 45 public void testValidateNoAddressingHeaders() throws Exception { 46 RMMessageContext rmMsgCtx = getRMMessageContext("server/validation/NoAddrHeadersMsg.xml"); 47 try { 48 MessageValidator.validate(rmMsgCtx, false); 49 } catch (AxisFault af) { 50 assertEquals(af.getFaultString(), Constants.FaultMessages.NO_ADDRESSING_HEADERS); 51 } 52 } 53 54 55 public void testValidateNoRMHeaders() throws Exception { 56 57 RMMessageContext rmMsgCtx = getRMMessageContext("server/validation/NoRMHeadersMsg.xml"); 58 MessageContext msgCtx = rmMsgCtx.getMsgContext(); 59 AddressingHeaders addrHeaders = new AddressingHeaders(rmMsgCtx.getMsgContext().getRequestMessage().getSOAPEnvelope()); 60 msgCtx.setProperty(org.apache.axis.message.addressing.Constants.ENV_ADDRESSING_REQUEST_HEADERS, 61 addrHeaders); 62 rmMsgCtx.setMsgContext(msgCtx); 63 64 try { 65 MessageValidator.validate(rmMsgCtx, false); 66 } catch (AxisFault af) { 67 assertEquals(af.getFaultString(), Constants.FaultMessages.NO_RM_HEADES); 68 } 69 } 70 71 public void testValidateMsgNoRollOver() throws Exception { 72 RMMessageContext rmMsgCtx = getRMMessageContext("server/validation/MsgNoRollOver.xml"); 73 MessageContext msgCtx = rmMsgCtx.getMsgContext(); 74 AddressingHeaders addrHeaders = new AddressingHeaders(rmMsgCtx.getMsgContext().getRequestMessage().getSOAPEnvelope()); 75 msgCtx.setProperty(org.apache.axis.message.addressing.Constants.ENV_ADDRESSING_REQUEST_HEADERS, 76 addrHeaders); 77 rmMsgCtx.setMsgContext(msgCtx); 78 79 try { 80 MessageValidator.validate(rmMsgCtx, false); 81 } catch (AxisFault af) { 82 assertEquals(af.getFaultString(), Constants.FaultMessages.MSG_NO_ROLLOVER); 83 } 84 } 85 86 public void testValidateUnknownSequence() throws Exception { 87 RMMessageContext rmMsgCtx = getRMMessageContext("server/validation/UnknownSequenceMsg.xml"); 88 MessageContext msgCtx = rmMsgCtx.getMsgContext(); 89 AddressingHeaders addrHeaders = new AddressingHeaders(rmMsgCtx.getMsgContext().getRequestMessage().getSOAPEnvelope()); 90 msgCtx.setProperty(org.apache.axis.message.addressing.Constants.ENV_ADDRESSING_REQUEST_HEADERS, 91 addrHeaders); 92 rmMsgCtx.setMsgContext(msgCtx); 93 94 try { 95 MessageValidator.validate(rmMsgCtx, false); 96 } catch (AxisFault af) { 97 assertEquals(af.getFaultString(), Constants.FaultMessages.UNKNOWN_SEQUENCE); 98 } 99 } 100 101 public void testForFaults() throws Exception { 102 RMMessageContext rmMsgCtx1 = getRMMessageContext("server/validation/MsgNo1Correct.xml"); 103 MessageContext msgCtx1 = rmMsgCtx1.getMsgContext(); 104 AddressingHeaders addrHeaders = new AddressingHeaders(rmMsgCtx1.getMsgContext().getRequestMessage().getSOAPEnvelope()); 105 msgCtx1.setProperty(org.apache.axis.message.addressing.Constants.ENV_ADDRESSING_REQUEST_HEADERS, 106 addrHeaders); 107 rmMsgCtx1.setMsgContext(msgCtx1); 108 rmMsgCtx1.setAddressingHeaders(addrHeaders); 109 110 111 SOAPService soapService1 = new SOAPService(); 112 msgCtx1.setService(soapService1); 113 114 115 RMProvider rmProvider = new RMProvider(); 116 rmProvider.processMessage(msgCtx1, null, null, null); 117 SOAPBody sb = msgCtx1.getResponseMessage().getSOAPEnvelope().getBody(); 118 SOAPFault sf = sb.getFault(); 119 assertEquals(sf.getFaultString(), Constants.FaultMessages.UNKNOWN_SEQUENCE); 120 121 122 } 123 124 } 125 | Popular Tags |