01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.saaj;
20:
21: import junit.framework.TestCase;
22:
23: import javax.xml.namespace.QName;
24: import javax.xml.soap.Detail;
25: import javax.xml.soap.DetailEntry;
26: import javax.xml.soap.MessageFactory;
27: import javax.xml.soap.SOAPBody;
28: import javax.xml.soap.SOAPConstants;
29: import javax.xml.soap.SOAPEnvelope;
30: import javax.xml.soap.SOAPFault;
31: import javax.xml.soap.SOAPHeader;
32: import javax.xml.soap.SOAPHeaderElement;
33: import javax.xml.soap.SOAPMessage;
34: import javax.xml.soap.SOAPPart;
35:
36: /**
37: *
38: */
39: public class SAAJDetailTest extends TestCase {
40: private SOAPMessage msg = null;
41: private SOAPPart sp = null;
42: private SOAPBody body = null;
43: private SOAPEnvelope envelope = null;
44: private SOAPHeader header = null;
45: private SOAPHeaderElement headerEle = null;
46:
47: protected void setUp() throws Exception {
48: msg = MessageFactory.newInstance().createMessage();
49: sp = msg.getSOAPPart();
50: envelope = sp.getEnvelope();
51: body = envelope.getBody();
52: header = envelope.getHeader();
53: headerEle = header.addHeaderElement(envelope.createName("foo",
54: "f", "foo-URI"));
55: headerEle.setActor("actor-URI");
56: }
57:
58: /*
59: * for soap version 1.1
60: */
61: public void testAddDetailEntry() throws Exception {
62: //Add a SOAPFault object to the SOAPBody
63: SOAPFault sf = body.addFault();
64: //Add a Detail object to the SOAPFault object
65: Detail d = sf.addDetail();
66: QName name = new QName("http://www.wombat.org/trader",
67: "GetLastTradePrice", "WOMBAT");
68: //Add a DetailEntry object to the Detail object
69: DetailEntry de = d.addDetailEntry(name);
70: assertNotNull(de);
71: assertTrue(de instanceof DetailEntry);
72: }
73:
74: /*
75: * for soap version 1.2
76: */
77: public void testAddDetailEntry2() throws Exception {
78: msg = MessageFactory.newInstance(
79: SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
80: sp = msg.getSOAPPart();
81: envelope = sp.getEnvelope();
82: body = envelope.getBody();
83:
84: //Add a SOAPFault object to the SOAPBody
85: SOAPFault sf = body.addFault();
86: //Add a Detail object to the SOAPFault object
87: Detail d = sf.addDetail();
88: QName name = new QName("http://www.wombat.org/trader",
89: "GetLastTradePrice", "WOMBAT");
90: //Add a DetailEntry object to the Detail object
91: DetailEntry de = d.addDetailEntry(name);
92: //Successfully created DetailEntry object
93: assertNotNull(de);
94: assertTrue(de instanceof DetailEntry);
95: }
96: }
|