KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > server > TCMessageValidator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

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 JavaDoc;
30 import javax.xml.soap.SOAPFault JavaDoc;
31
32
33 public class TCMessageValidator extends AbstractTestCase {
34     /**
35      * Constructor.
36      */

37     public TCMessageValidator(String JavaDoc testName) {
38         super(testName);
39     }
40
41     protected void setUp() throws Exception JavaDoc {
42
43     }
44
45     public void testValidateNoAddressingHeaders() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc sb = msgCtx1.getResponseMessage().getSOAPEnvelope().getBody();
118         SOAPFault JavaDoc sf = sb.getFault();
119         assertEquals(sf.getFaultString(), Constants.FaultMessages.UNKNOWN_SEQUENCE);
120
121
122     }
123
124 }
125
Popular Tags