KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > PrefixesTest


1 /*
2  * Copyright 2004,2005 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 package org.apache.axis2.saaj;
17
18 import junit.framework.TestCase;
19
20 import javax.xml.soap.*;
21 import java.io.ByteArrayOutputStream JavaDoc;
22
23 /**
24  * @author Ashutosh Shahi
25  *
26  */

27 public class PrefixesTest extends TestCase {
28     
29     public PrefixesTest(String JavaDoc name) {
30         super(name);
31     }
32     
33     public void testAddingPrefixesForChildElements() throws Exception JavaDoc {
34         MessageFactory factory = MessageFactory.newInstance();
35         SOAPMessage msg = factory.createMessage();
36         SOAPPart sp = msg.getSOAPPart();
37         SOAPEnvelope se = sp.getEnvelope();
38         SOAPBody sb = se.getBody();
39         SOAPElement el1 = sb.addBodyElement(se.createName
40                 ("element1", "prefix1", "http://www.sun.com"));
41         SOAPElement el2 = el1.addChildElement(se.createName
42                 ("element2", "prefix2", "http://www.apache.org"));
43         
44         org.apache.axis2.soap.SOAPEnvelope omEnv = ((SOAPEnvelopeImpl)se).getOMEnvelope();
45         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
46         msg.writeTo(baos);
47         
48         String JavaDoc xml = new String JavaDoc(baos.toByteArray());
49         System.out.println(xml);
50         assertTrue(xml.indexOf("prefix1") != -1);
51         assertTrue(xml.indexOf("prefix2") != -1);
52         assertTrue(xml.indexOf("http://www.sun.com") != -1);
53         assertTrue(xml.indexOf("http://www.apache.org") != -1);
54     }
55     
56    /* public void testAttribute() throws Exception {
57         String soappacket = "<SOAP-ENV:Envelope xmlns:SOAP-ENV =\"http://schemas.xmlsoap.org/soap/envelope/\"" +
58                             "xmlns:xsi =\"http://www.w3.org/1999/XMLSchema-instance\"" +
59                             "xmlns:xsd =\"http://www.w3.org/1999/XMLSchema\">" +
60                             "<SOAP-ENV:Body>" +
61                             "<helloworld name=\"tester\" />" +
62                             "</SOAP-ENV:Body>" +
63                             "</SOAP-ENV:Envelope>";
64         SOAPMessage msg = MessageFactory.newInstance().createMessage(new MimeHeaders(), new ByteArrayInputStream(soappacket.getBytes()));
65         SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
66         msg.writeTo(System.out);
67
68         SOAPElement ele = (SOAPElement) body.getChildElements().next();
69         java.util.Iterator attit = ele.getAllAttributes();
70
71         System.out.println(attit.next().getClass());
72         
73         javax.xml.soap.Name n = (javax.xml.soap.Name) attit.next();
74         //assertEquals("Test fail prefix problem",n.getQualifiedName(),"name");
75     }*/

76
77 }
78
Popular Tags