summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org')
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java64
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java57
-rwxr-xr-xbranches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java82
-rwxr-xr-xbranches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java87
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java110
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java81
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java79
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java65
-rw-r--r--branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java60
9 files changed, 685 insertions, 0 deletions
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java
new file mode 100644
index 0000000000..182156c7ac
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * 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.databinding.sdo;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import commonj.sdo.DataObject;
+
+/**
+ *
+ */
+public class DataObject2StringTestCase extends SDOTransformerTestCaseBase {
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataType<QName>(binding, PurchaseOrderType.class, ORDER_QNAME);
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataType<Class<String>>(String.class, String.class);
+ }
+
+ public final void testTransform() {
+ String xml = new DataObject2String().transform(dataObject, context);
+ Assert.assertTrue(xml.indexOf("<city>San Jose</city>") != -1);
+ DataObject po = new String2DataObject().transform(xml, reversedContext);
+ Assert.assertTrue(po instanceof PurchaseOrderType);
+ PurchaseOrderType orderType = (PurchaseOrderType)po;
+ Assert.assertEquals("San Jose", orderType.getBillTo().getCity());
+ }
+
+ public final void testXML() {
+ String xml =
+ "<foo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ + "xmlns:ipo=\"http://www.example.com/IPO\" xsi:type=\"ipo:USAddress\"/>";
+ DataObject dataObject = new String2DataObject().transform(xml, reversedContext);
+ context.setSourceDataType(new DataType<QName>(DataObject.class.getName(), DataObject.class, null));
+ xml = new DataObject2String().transform(dataObject, context);
+ Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\""));
+ }
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..7a1f03e36f
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * 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.databinding.sdo;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+
+/**
+ *
+ */
+public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataType<QName>(binding, PurchaseOrderType.class, ORDER_QNAME);
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataType<Class<XMLStreamReader>>(XMLStreamReader.class, XMLStreamReader.class);
+ }
+
+ public final void testTransform() throws XMLStreamException {
+ XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context);
+ while (reader.hasNext()) {
+ int event = reader.next();
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ break;
+ }
+ }
+ new XMLStreamReader2DataObject().transform(reader, reversedContext);
+ }
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java
new file mode 100755
index 0000000000..f38e0426cb
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * 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.databinding.sdo;
+
+import java.io.StringReader;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import commonj.sdo.helper.XSDHelper;
+
+public class DataObjectLoaderTestCase extends TestCase {
+
+ private XSDHelper xsdHelper = XSDHelper.INSTANCE;
+
+ private QName name = new QName("http://www.osoa.org/xmlns/mock/0.9", "implementation.mock");
+
+ private String xml =
+ "<module name=\"m\" xmlns=\"http://www.osoa.org/xmlns/sca/0.9\" " + "xmlns:mock=\"http://www.osoa.org/xmlns/mock/0.9\" "
+ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ + "xsi:schemaLocation=\"http://www.osoa.org/xmlns/mock/0.9 "
+ + "sca-implementation-mock.xsd http://www.osoa.org/xmlns/sca/0.9 sca-core.xsd \">"
+ + "<component name=\"c\"><mock:implementation.mock myAttr=\"helloworld.HelloWorldImpl\" />"
+ + "</component></module>";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ URL url = getClass().getClassLoader().getResource("model/sca-implementation-mock.xsd");
+ // URL url =
+ // getClass().getClassLoader().getResource("model/sca-core.xsd");
+ xsdHelper.define(url.openStream(), url.toExternalForm());
+ }
+
+ public void testLoader() throws Exception {
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml));
+ int event = reader.getEventType();
+ while (!(event == XMLStreamConstants.START_ELEMENT && reader.getName().equals(name)) && reader.hasNext()) {
+ event = reader.nextTag();
+ }
+ DataObjectLoader loader = new DataObjectLoader(null, name.getNamespaceURI(), name.getLocalPart());
+ DeploymentContext context =
+ new RootDeploymentContext(getClass().getClassLoader(), inputFactory, new CompositeScopeContainer(null),
+ null);
+ ModelDataObject modelObject = (ModelDataObject)loader.load(null, null, reader, context);
+ Assert.assertNotNull(modelObject.getDataObject());
+ Assert.assertTrue(modelObject.getDataObject().getString("myAttr").equals("helloworld.HelloWorldImpl"));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
new file mode 100755
index 0000000000..e87526bb9a
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
@@ -0,0 +1,87 @@
+/*
+ * 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.databinding.sdo;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import com.example.ipo.sdo.SdoFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImportSDOLoaderTestCase extends TestCase {
+ private static boolean inited;
+
+ private ImportSDOLoader loader;
+ private XMLInputFactory xmlFactory;
+ private DeploymentContext deploymentContext;
+
+ public void testMinimal() throws XMLStreamException, LoaderException {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO);
+ }
+
+ public void testLocation() throws XMLStreamException, LoaderException {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0' location='ipo.xsd'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO);
+ }
+
+ public void testFactory() throws XMLStreamException, LoaderException {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0' "
+ + "factory='org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertFalse(inited);
+ assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO);
+ assertTrue(inited);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ loader = new ImportSDOLoader(null);
+ xmlFactory = XMLInputFactory.newInstance();
+ deploymentContext = new RootDeploymentContext(getClass().getClassLoader(), xmlFactory, null, null);
+ }
+
+ protected XMLStreamReader getReader(String xml) throws XMLStreamException {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
+ reader.next();
+ return reader;
+ }
+
+ public static class MockFactory {
+ public static final Object INSTANCE = SdoFactory.INSTANCE;
+
+ static {
+ ImportSDOLoaderTestCase.inited = true;
+ }
+ }
+}
+
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java
new file mode 100644
index 0000000000..e2145f1a5c
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.databinding.sdo;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.idl.XMLType;
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import com.example.ipo.sdo.SdoFactory;
+import com.example.ipo.sdo.USAddress;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ *
+ */
+public class SDODataBindingTestCase extends TestCase {
+ protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder");
+ private SDODataBinding binding;
+ private HelperContext context;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ binding = new SDODataBinding();
+ context = HelperProvider.getDefaultContext();
+ SdoFactory.INSTANCE.register(context);
+ }
+
+ public final void testIntrospect() {
+ DataType dataType = new DataType(DataObject.class, null);
+ boolean yes = binding.introspect(dataType, null);
+ assertTrue(yes);
+ assertTrue(dataType.getDataBinding().equals(binding.getName()));
+ assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN);
+ dataType = new DataType(PurchaseOrderType.class, null);
+ yes = binding.introspect(dataType, null);
+ assertTrue(yes);
+ assertEquals(PurchaseOrderType.class, dataType.getPhysical());
+ assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical())
+ .getTypeName());
+ dataType = new DataType(USAddress.class, null);
+ yes = binding.introspect(dataType, null);
+ assertTrue(yes);
+ assertEquals(USAddress.class, dataType.getPhysical());
+ assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical())
+ .getTypeName());
+ }
+
+ public final void testCopyRoot() {
+ PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType();
+ po.setComment("Comment");
+ Object copy = binding.copy(po);
+ assertTrue(copy instanceof PurchaseOrderType);
+ assertTrue(po != copy);
+ assertTrue(context.getEqualityHelper().equal((DataObject)po, (DataObject)copy));
+ assertEquals("Comment", ((PurchaseOrderType)copy).getComment());
+ }
+
+ public final void testCopyNonRoot() {
+ USAddress address = SdoFactory.INSTANCE.createUSAddress();
+ address.setCity("San Jose");
+ Object copy = binding.copy(address);
+ assertTrue(copy instanceof USAddress);
+ assertTrue(address != copy);
+ assertTrue(context.getEqualityHelper().equal((DataObject)address, (DataObject)copy));
+ assertEquals("San Jose", ((USAddress)copy).getCity());
+ }
+
+ public final void testCopyXMLDocument() {
+ PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType();
+ po.setComment("Comment");
+ XMLDocument doc =
+ context.getXMLHelper().createDocument((DataObject)po,
+ ORDER_QNAME.getNamespaceURI(),
+ ORDER_QNAME.getLocalPart());
+ Object copy = binding.copy(doc);
+ assertTrue(copy instanceof XMLDocument);
+ XMLDocument docCopy = (XMLDocument)copy;
+ assertTrue(doc != copy);
+ assertTrue(context.getEqualityHelper().equal((DataObject)po, docCopy.getRootObject()));
+ assertEquals("Comment", ((PurchaseOrderType)docCopy.getRootObject()).getComment());
+ }
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java
new file mode 100644
index 0000000000..8226891c35
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * 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.databinding.sdo;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.idl.XMLType;
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.stock.sdo.InvalidSymbolFault;
+import com.example.stock.sdo.StockFactory;
+import com.example.stock.sdo.fault.InvalidSymbolFault_Exception;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ * Test case for SDOExceptionHandler
+ */
+public class SDOExceptionHandlerTestCase extends TestCase {
+ // FIXME: Tuscany SDO impl uses _._type for anonymouse type, by the SDO
+ // spec, it should be same as the
+ // enclosing element/attribute name
+ private SDOExceptionHandler handler;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.handler = new SDOExceptionHandler();
+ StockFactory.INSTANCE.register(HelperProvider.getDefaultContext());
+ }
+
+ public void testGetFaultType() {
+ DataType execType = new DataType<XMLType>(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN);
+ DataType<?> dataType = handler.getFaultType(execType);
+ assertEquals(InvalidSymbolFault.class, dataType.getPhysical());
+ assertEquals(InvalidSymbolFault_Exception.FAULT_ELEMENT, ((XMLType) dataType.getLogical()).getElementName());
+ assertEquals(SDODataBinding.NAME, dataType.getDataBinding());
+ }
+
+ public void testCreate() {
+ DataType execType = new DataType<XMLType>(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN);
+ DataType<?> faultType = handler.getFaultType(execType);
+ InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault();
+ fault.setMessage("ABC");
+ fault.setSymbol("IBM0");
+ DataType<DataType> exType = new DataType<DataType>(InvalidSymbolFault_Exception.class, faultType);
+ Exception ex = handler.createException(exType, "Invalid symbol", fault, null);
+ assertTrue(ex instanceof InvalidSymbolFault_Exception);
+ InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex;
+ assertEquals("Invalid symbol", exception.getMessage());
+ assertSame(fault, exception.getFaultInfo());
+ }
+
+ public void testGetFaultInfo() {
+ InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault();
+ fault.setMessage("ABC");
+ fault.setSymbol("IBM0");
+ InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault);
+ Object faultInfo = handler.getFaultInfo(exception);
+ assertSame(fault, faultInfo);
+ }
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java
new file mode 100644
index 0000000000..58a05fcf9b
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java
@@ -0,0 +1,79 @@
+/*
+ * 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.databinding.sdo;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.TransformationContextImpl;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import com.example.ipo.sdo.SdoFactory;
+import com.example.ipo.sdo.USAddress;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ * The base class for SDO-related test cases
+ */
+public abstract class SDOTransformerTestCaseBase extends TestCase {
+ protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder");
+
+ protected HelperContext helperContext;
+ protected String binding = DataObject.class.getName();
+ protected TransformationContext context;
+ protected TransformationContext reversedContext;
+ protected DataObject dataObject;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ helperContext = HelperProvider.getDefaultContext();
+ SdoFactory.INSTANCE.register(helperContext);
+
+ context = new TransformationContextImpl();
+ context.setSourceDataType(getSourceDataType());
+ context.setTargetDataType(getTargetDataType());
+
+ reversedContext = new TransformationContextImpl();
+ reversedContext.setSourceDataType(getTargetDataType());
+ reversedContext.setTargetDataType(getSourceDataType());
+
+ PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType();
+ USAddress address = SdoFactory.INSTANCE.createUSAddress();
+ address.setCity("San Jose");
+ address.setStreet("123 ABC St");
+ address.setState("CA");
+ address.setStreet("95131");
+ po.setBillTo(address);
+ dataObject = (DataObject) po;
+ }
+
+ protected abstract DataType<?> getSourceDataType();
+
+ protected abstract DataType<?> getTargetDataType();
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java
new file mode 100644
index 0000000000..3ddd1c85dd
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java
@@ -0,0 +1,65 @@
+/*
+ * 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.databinding.sdo;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SDOWrapperHandlerTestCase {
+ private HelperContext context;
+ private SDOWrapperHandler handler;
+
+ @Before
+ public void setUp() throws Exception {
+ context = SDOUtil.createHelperContext();
+ handler = new SDOWrapperHandler();
+ }
+
+ @Test
+ public void testWrapperAnyType() throws Exception {
+ XMLHelper xmlHelper = context.getXMLHelper();
+ XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
+ List children = handler.getChildren(document);
+ assertEquals(5, children.size());
+ }
+
+ @Test
+ public void testWrapper() throws Exception {
+ XSDHelper xsdHelper = context.getXSDHelper();
+ xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
+ XMLHelper xmlHelper = context.getXMLHelper();
+ XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
+ List children = handler.getChildren(document);
+ assertEquals(5, children.size());
+ }
+
+}
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..c58636decc
--- /dev/null
+++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java
@@ -0,0 +1,60 @@
+/*
+ * 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.databinding.sdo;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ *
+ */
+public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataType<QName>(XMLDocument.class.getName(), XMLDocument.class, ORDER_QNAME);
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataType<Class<XMLStreamReader>>(XMLStreamReader.class, XMLStreamReader.class);
+ }
+
+ public final void testTransform() throws XMLStreamException {
+ XMLDocument document =
+ helperContext.getXMLHelper().createDocument(dataObject,
+ ORDER_QNAME.getNamespaceURI(),
+ ORDER_QNAME.getLocalPart());
+ XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context);
+ XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext);
+ Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), document2.getRootElementURI());
+ Assert.assertEquals(ORDER_QNAME.getLocalPart(), document2.getRootElementName());
+ Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType);
+ }
+
+}