01: /*
02: * Copyright 2004,2005 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.schema.rampart;
17:
18: import junit.framework.TestCase;
19: import org.w3.www._2005._05.xmlmime.TestExtension;
20: import org.w3.www._2005._05.xmlmime.Base64Binary;
21: import org.w3.www._2005._05.xmlmime.ContentType_type0;
22: import org.apache.axiom.attachments.ByteArrayDataSource;
23: import org.apache.axiom.om.OMElement;
24: import org.apache.axiom.om.OMAbstractFactory;
25: import org.apache.axiom.om.util.StAXUtils;
26: import org.apache.axis2.databinding.ADBException;
27:
28: import javax.activation.DataHandler;
29: import javax.xml.stream.XMLStreamReader;
30: import javax.xml.stream.XMLStreamException;
31: import java.io.ByteArrayInputStream;
32:
33: public class RampartTest extends TestCase {
34:
35: public void testExtension() {
36: TestExtension testExtension = new TestExtension();
37:
38: Base64Binary base64Binary = new Base64Binary();
39: testExtension.setTestExtension(base64Binary);
40:
41: String testString = "test base 64 eleemnt";
42: DataHandler dataHandler = new DataHandler(
43: new ByteArrayDataSource(testString.getBytes()));
44: base64Binary.setBase64Binary(dataHandler);
45:
46: ContentType_type0 contentType_type0 = new ContentType_type0();
47: contentType_type0.setContentType_type0("test string");
48: base64Binary.setContentType(contentType_type0);
49:
50: try {
51: OMElement omElement = testExtension.getOMElement(
52: TestExtension.MY_QNAME, OMAbstractFactory
53: .getOMFactory());
54: String omElementString = omElement.toStringWithConsume();
55: System.out.println("OM String " + omElementString);
56: XMLStreamReader xmlReader = StAXUtils
57: .createXMLStreamReader(new ByteArrayInputStream(
58: omElementString.getBytes()));
59: TestExtension result = TestExtension.Factory
60: .parse(xmlReader);
61:
62: } catch (ADBException e) {
63: fail();
64: } catch (XMLStreamException e) {
65: fail();
66: } catch (Exception e) {
67: fail();
68: }
69: }
70: }
|