diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-22 09:11:51 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-22 09:11:51 +0000 |
commit | 0d7533759f027a0fafc5844210ddf4e35122c758 (patch) | |
tree | cd7e7bedbd53b9e04541ea6ba48a5b44a5460e6d /sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java | |
parent | 40e207beb6ed5c979bdedc71ebc735ba9295ecfe (diff) |
Create branch for next release
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@966547 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
11 files changed, 842 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..5a0208b290 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,70 @@ +/* + * 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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + * @version $Rev$ $Date$ + */ +public class InvalidSymbolFault_Exception extends Exception { + private static final long serialVersionUID = 8602157311925253920L; + + /** + * Generated QName for the fault element + */ + public static final QName FAULT_ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java new file mode 100644 index 0000000000..012af9ed1c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java @@ -0,0 +1,61 @@ +/* + * 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.databinding.sdo; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2NodeTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType<?> getSourceDataType() { + return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataTypeImpl<Class<String>>(String.class, String.class); + } + + public final void testTransform() { + Node node = new DataObject2Node().transform(dataObject, context); + Assert.assertNotNull(node); + Element element = (Element) node; + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + DataObject po = new Node2DataObject(new DefaultExtensionPointRegistry()).transform(node, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..44d11cd586 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.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.sca.databinding.sdo; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType<?> getSourceDataType() { + return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataTypeImpl<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 DataTypeImpl<XMLType>(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..c2a9f46059 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java @@ -0,0 +1,76 @@ +/* + * 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.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.xml.Node2String; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; +import commonj.sdo.helper.EqualityHelper; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType<?> getSourceDataType() { + return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataTypeImpl<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; + } + } + DataObject d = new XMLStreamReader2DataObject().transform(reader, reversedContext); + assertNotNull(d); + assertTrue(EqualityHelper.INSTANCE.equal(dataObject, d)); + } + + public final void testTransform1() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + XMLStreamReader2Node t2 = new XMLStreamReader2Node(new DefaultExtensionPointRegistry()); + org.w3c.dom.Node node = t2.transform(reader, context); + assertNotNull(node); + Node2String t3 = new Node2String(new DefaultExtensionPointRegistry()); + String xml = t3.transform(node, context); + assertTrue(xml.contains("xmlns:xsi")); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java new file mode 100644 index 0000000000..1fcae3cb73 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java @@ -0,0 +1,103 @@ +/* + * 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.databinding.sdo; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.example.ipo.sdo.SdoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessorTestCase { + private static boolean inited; + + private static ExtensionPointRegistry registry; + private static ImportSDOProcessor loader; + private static XMLInputFactory xmlFactory; + + @Test + public void testMinimal() throws Exception { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1'/>"; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader, new ProcessorContext(registry)) instanceof ImportSDO); + } + + @Test + public void testLocation() throws Exception { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1' location='ipo.xsd'/>"; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader, new ProcessorContext(registry)) instanceof ImportSDO); + } + + @Test + public void testFactory() throws Exception { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1' " + "factory='" + + MockFactory.class.getName() + + "'/>"; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + ProcessorContext context = new ProcessorContext(registry); + ImportSDO importSDO = loader.read(reader, context); + assertNotNull(importSDO); + ModelResolver resolver = new TestModelResolver(); + resolver.addModel(new ClassReference(MockFactory.class), context); + loader.resolve(importSDO, resolver, context); + assertTrue(inited); + } + + @BeforeClass + public static void setUp() throws Exception { + registry = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + loader = new ImportSDOProcessor(registry); + xmlFactory = factories.getFactory(XMLInputFactory.class); + } + + 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 { + ImportSDOProcessorTestCase.inited = true; + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java new file mode 100644 index 0000000000..e0d1c9bf12 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java @@ -0,0 +1,55 @@ +/* + * 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.databinding.sdo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.junit.Test; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class SDOContextHelperTestCase { + @Test + public void testGenerateSchema() throws IOException { + HelperContext context = SDOUtil.createHelperContext(); + URL url = getClass().getResource("/ipo.xsd"); + Assert.assertNotNull(url); + InputStream is = url.openStream(); + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(is, url.toExternalForm()); + TypeHelper typeHelper = context.getTypeHelper(); + Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType"); + Assert.assertNotNull(type); + /* + SDOContextHelper.generateSchema(context, Arrays.asList(type)); + */ + } +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..400b424a97 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java @@ -0,0 +1,115 @@ +/* + * 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.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +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; + +/** + * + * @version $Rev$ $Date$ + */ +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() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(new DefaultExtensionPointRegistry()); + context = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(context); + } + + public final void testIntrospect() { + Operation op = null; + DataType dataType = new DataTypeImpl<Class>(DataObject.class, null); + boolean yes = binding.introspect(dataType, op); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl<Class>(USAddress.class, null); + yes = binding.introspect(dataType, op); + 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, null, null, null, null); + 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, null, null, null, null); + 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, null, null, null, null); + 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/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..4d415f2895 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,84 @@ +/* + * 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.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.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 + * + * @version $Rev$ $Date$ + */ +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() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + new SDODataBinding(new DefaultExtensionPointRegistry()); + 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/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..2326d1b93b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java @@ -0,0 +1,85 @@ +/* + * 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.databinding.sdo; + +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandlerTestCase extends TestCase { + private HelperContext context; + private SDOWrapperHandler handler; + + @Override + public void setUp() throws Exception { + new SDODataBinding(new DefaultExtensionPointRegistry()); + context = SDOUtil.createHelperContext(); + handler = new SDOWrapperHandler(); + } + + public void testWrapperAnyType() throws Exception { + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + Operation op = new OperationImpl(); + List children = handler.getChildren(document, op, true); + assertEquals(5, children.size()); + } + + 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")); + Operation op = new OperationImpl(); + List children = handler.getChildren(document, op, true); + assertEquals(5, children.size()); + } + + public void testCreate() { + HelperContext context = HelperProvider.getDefaultContext(); + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + ElementInfo element = new ElementInfo(new QName("http://www.example.com/wrapper", "op"), null); + Operation op = new OperationImpl(); + WrapperInfo wrapperInfo = new WrapperInfo(SDODataBinding.NAME, element, null, null, null); + op.setWrapper(wrapperInfo); + DataObject wrapper = (DataObject) handler.create(op, true); + assertNotNull(wrapper); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java new file mode 100644 index 0000000000..3f742b49a3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.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.sca.databinding.sdo; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map<Object, Object> map = new HashMap<Object, Object>(); + + public TestModelResolver() { + } + + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved, ProcessorContext context) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved, ProcessorContext context) { + return map.remove(resolved); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..2beadc5b61 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.api.SDOUtil; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.helper.XMLDocument; + +/** + * + * @version $Rev$ $Date$ + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType<?> getSourceDataType() { + return new DataTypeImpl<XMLType>(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataTypeImpl<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); + } + +} |