summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/1.6-TUSCANY-3909/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java
blob: 7d49fb71123faeeb3d9a73bede405603dc16af28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.tuscany.sca.core.databinding.transformers;

//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT;
//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import javax.xml.namespace.QName;

import junit.framework.TestCase;

//import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl;
//import org.apache.tuscany.databinding.impl.MediatorImpl;
//import org.apache.tuscany.databinding.impl.TransformationContextImpl;
//import org.apache.tuscany.databinding.impl.TransformerRegistryImpl;
//import org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer;
//import org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer;
//import org.apache.tuscany.databinding.xml.DOMDataBinding;
//import org.apache.tuscany.databinding.xml.Node2String;
//import org.apache.tuscany.databinding.xml.String2Node;
//import org.apache.tuscany.interfacedef.DataType;
//import org.apache.tuscany.interfacedef.Operation;
//import org.apache.tuscany.interfacedef.impl.DataTypeImpl;
//import org.apache.tuscany.interfacedef.impl.OperationImpl;
//import org.apache.tuscany.interfacedef.util.ElementInfo;
//import org.apache.tuscany.interfacedef.util.TypeInfo;
//import org.apache.tuscany.interfacedef.util.WrapperInfo;
//import org.apache.tuscany.interfacedef.util.XMLType;
//import org.apache.tuscany.spi.databinding.DataBindingRegistry;
//import org.apache.tuscany.spi.databinding.TransformationContext;
//import org.apache.tuscany.spi.databinding.extension.DOMHelper;
//import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
//import org.w3c.dom.Document;
//import org.w3c.dom.Element;

public class IDLTransformerTestCaseFIXME extends TestCase {
//    private static final String IPO_XML = "<?xml version=\"1.0\"?>" + "<order1"
//                                          + "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
//                                          + "  xmlns:ipo=\"http://www.example.com/IPO\""
//                                          + "  xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
//                                          + "  orderDate=\"1999-12-01\">"
//                                          + "  <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
//                                          + "    <name>Helen Zoe</name>"
//                                          + "    <street>47 Eden Street</street>"
//                                          + "    <city>Cambridge</city>"
//                                          + "    <postcode>CB1 1JR</postcode>"
//                                          + "  </shipTo>"
//                                          + "  <billTo xsi:type=\"ipo:USAddress\">"
//                                          + "    <name>Robert Smith</name>"
//                                          + "    <street>8 Oak Avenue</street>"
//                                          + "    <city>Old Town</city>"
//                                          + "    <state>PA</state>"
//                                          + "    <zip>95819</zip>"
//                                          + "  </billTo>"
//                                          + "  <items>"
//                                          + "    <item partNum=\"833-AA\">"
//                                          + "      <productName>Lapis necklace</productName>"
//                                          + "      <quantity>1</quantity>"
//                                          + "      <USPrice>99.95</USPrice>"
//                                          + "      <ipo:comment>Want this for the holidays</ipo:comment>"
//                                          + "      <shipDate>1999-12-05</shipDate>"
//                                          + "    </item>"
//                                          + "  </items>"
//                                          + "</order1>";
//
//    private static final String URI_ORDER_XSD = "http://example.com/order.xsd";
//
//    /**
//     * @see junit.framework.TestCase#setUp()
//     */
//    protected void setUp() throws Exception {
//        super.setUp();
//    }
//
//    public void testTransform() throws Exception {
//        List<DataType> types0 = new ArrayList<DataType>();
//        DataType<XMLType> wrapperType = new DataTypeImpl<XMLType>(null, Object.class,
//                                                                  new XMLType(new QName(URI_ORDER_XSD,
//                                                                                        "checkOrderStatus"), null));
//        types0.add(wrapperType);
//        DataType<List<DataType>> inputType0 = new DataTypeImpl<List<DataType>>(IDL_INPUT,
//                                                                                                 Object[].class, types0);
//
//        List<DataType> types1 = new ArrayList<DataType>();
//        DataType<XMLType> customerIdType = new DataTypeImpl<XMLType>(
//                                                                     null,
//                                                                     Object.class,
//                                                                     new XMLType(
//                                                                                 new QName(URI_ORDER_XSD, "customerId"),
//                                                                                 null));
//        DataType<XMLType> orderType = new DataTypeImpl<XMLType>(null, Object.class,
//                                                                new XMLType(new QName(URI_ORDER_XSD, "order"), null));
//        DataType<XMLType> flagType = new DataTypeImpl<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD,
//                                                                                                         "flag"), null));
//        types1.add(customerIdType);
//        types1.add(orderType);
//        types1.add(flagType);
//
//        DataType<XMLType> statusType = new DataTypeImpl<XMLType>(null, Object.class,
//                                                                 new XMLType(new QName(URI_ORDER_XSD, "status"), null));
//        DataType<XMLType> responseType = new DataTypeImpl<XMLType>(null, Object.class,
//                                                                   new XMLType(new QName(URI_ORDER_XSD,
//                                                                                         "checkOrderStatusResponse"),
//                                                                               null));
//
//        Operation op = new OperationImpl("checkOrderStatus");
//        op.setInputType(inputType0);
//        op.setOutputType(responseType);
////        op.setDataBinding(DOMDataBinding.NAME);
////
////        inputType0.setOperation(op);
//        op.setWrapperStyle(true);
//        ElementInfo inputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null,
//                                                                                                              false,
//                                                                                                              null));
////        wrapperType.setMetadata(ElementInfo.class.getName(), inputElement);
//
//        ElementInfo customerId = new ElementInfo(new QName("", "customerId"),
//                                                 SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string"));
//        ElementInfo order = new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null));
//        ElementInfo flag = new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int"));
//
////        customerIdType.setMetadata(ElementInfo.class.getName(), customerId);
////        orderType.setMetadata(ElementInfo.class.getName(), order);
////        flagType.setMetadata(ElementInfo.class.getName(), flag);
////
////        customerIdType.setOperation(op);
////        orderType.setOperation(op);
////        flagType.setOperation(op);
//
//        List<ElementInfo> inputElements = new ArrayList<ElementInfo>();
//        inputElements.add(customerId);
//        inputElements.add(order);
//        inputElements.add(flag);
//
//        ElementInfo statusElement = new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES
//            .get("string"));
//
////        statusType.setMetadata(ElementInfo.class.getName(), statusElement);
////        statusType.setOperation(op);
//
//        List<ElementInfo> outputElements = new ArrayList<ElementInfo>();
//        outputElements.add(statusElement);
//
//        ElementInfo outputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"),
//                                                    new TypeInfo(null, false, null));
//
////        responseType.setMetadata(ElementInfo.class.getName(), inputElement);
////        responseType.setOperation(op);
//
//        WrapperInfo wrapperInfo = new WrapperInfo(DOMDataBinding.NAME, inputElement, outputElement, inputElements,
//                                                  outputElements);
//        op.setWrapper(wrapperInfo);
////        op.setDataBinding(DOMDataBinding.NAME);
//
//        MediatorImpl m = new MediatorImpl();
//        TransformerRegistryImpl tr = new TransformerRegistryImpl();
//        tr.registerTransformer(new String2Node());
//        tr.registerTransformer(new Node2String());
//        tr.registerTransformer(new DOMNode2JavaBeanTransformer());
//        tr.registerTransformer(new JavaBean2DOMNodeTransformer());
//        m.setTransformerRegistry(tr);
//        DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl();
//        dataBindingRegistry.register(new DOMDataBinding());
//        m.setDataBindingRegistry(dataBindingRegistry);
//
//        Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)};
//        Input2InputTransformer t = new Input2InputTransformer();
//        t.setMediator(m);
//
//        TransformationContext context = new TransformationContextImpl();
//        context.setSourceOperation(op);
//        List<DataType<Class>> types = new ArrayList<DataType<Class>>();
//        types.add(new DataTypeImpl<Class>(Object.class.getName(), String.class, String.class));
//        types.add(new DataTypeImpl<Class>("java.lang.String", String.class, String.class));
//        types.add(new DataTypeImpl<Class>(Object.class.getName(), int.class, int.class));
//        DataType<List<DataType<Class>>> inputType1 = new DataTypeImpl<List<DataType<Class>>>(IDL_INPUT, Object[].class,
//                                                                                             types);
//        context.setSourceDataType(inputType1);
//        context.setTargetDataType(op.getInputType());
//        Object[] results = t.transform(source, context);
//        assertEquals(1, results.length);
//        assertTrue(results[0] instanceof Element);
//        Element element = (Element)results[0];
//        assertEquals("http://example.com/order.xsd", element.getNamespaceURI());
//        assertEquals("checkOrderStatus", element.getLocalName());
//
//        TransformationContext context1 = new TransformationContextImpl();
//        DataType<DataType> sourceType = new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, op.getOutputType());
//
//        context1.setSourceDataType(sourceType);
//        DataType<DataType> targetType = new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class,
//                                                                   new DataTypeImpl<Class>("java.lang.Object",
//                                                                                           String.class, String.class));
//        context1.setTargetDataType(targetType);
//
//        Document factory = DOMHelper.newDocument();
//        Element responseElement = factory
//            .createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse");
//        Element status = factory.createElement("status");
//        responseElement.appendChild(status);
//        status.appendChild(factory.createTextNode("shipped"));
//        Output2OutputTransformer t2 = new Output2OutputTransformer();
//        t2.setMediator(m);
//        Object st = t2.transform(responseElement, context1);
//        assertEquals("shipped", st);
//
//    }
//
}