diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org')
10 files changed, 0 insertions, 772 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java deleted file mode 100644 index 012af9ed1c..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java deleted file mode 100644 index 44d11cd586..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java deleted file mode 100644 index c2a9f46059..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java deleted file mode 100644 index 1fcae3cb73..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java deleted file mode 100644 index e0d1c9bf12..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java deleted file mode 100644 index 400b424a97..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java deleted file mode 100644 index 4d415f2895..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java deleted file mode 100644 index 2326d1b93b..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java deleted file mode 100644 index 3f742b49a3..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java deleted file mode 100644 index 2beadc5b61..0000000000 --- a/sca-java-2.x/branches/2.0-Beta2/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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); - } - -} |