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:
20: package org.apache.axis2.saaj;
21:
22: import junit.framework.TestCase;
23:
24: import javax.xml.soap.MessageFactory;
25: import javax.xml.soap.SOAPMessage;
26: import java.io.ByteArrayInputStream;
27: import java.io.ByteArrayOutputStream;
28:
29: /** Ref: JIRA- Axis2-517 */
30: public class SOAPNamespaceTest extends TestCase {
31:
32: public SOAPNamespaceTest(String arg0) {
33: super (arg0);
34: }
35:
36: public void test() {
37: try {
38: String xml = "<?xml version='1.0' ?><env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Body/></env:Envelope>";
39:
40: SOAPMessage msg = MessageFactory.newInstance()
41: .createMessage(null,
42: new ByteArrayInputStream(xml.getBytes()));
43: msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
44: ByteArrayOutputStream baos = new ByteArrayOutputStream();
45: msg.writeTo(baos);
46: String producedMag = new String(baos.toByteArray());
47: String[] splitParts = producedMag
48: .split("http://schemas.xmlsoap.org/soap/envelope");
49: assertEquals("Extra namespace declaration", 2,
50: splitParts.length);
51: } catch (Exception e) {
52: fail(e.getMessage());
53: }
54: }
55:
56: }
|