From 1fb6a28a73ca17dbb8c4b3059db590e2f9620943 Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 3 Aug 2011 09:21:41 +0000 Subject: Correct tag name git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1153404 13f79535-47bb-0310-9956-ffa450edef68 --- .../databinding/extension/DOMHelperTestCase.java | 58 ------ .../extension/DataBindingExtensionTestCase.java | 86 --------- .../SimpleTypeMapperExtensionTestCase.java | 124 ------------- .../extension/TransformerExtensionTestCase.java | 77 -------- .../extension/XSDDataTypeConverterTestCase.java | 64 ------- .../impl/DataBindingRegistryImplTestCase.java | 97 ---------- .../sca/databinding/impl/DataBindingTestCase.java | 49 ----- .../databinding/impl/DirectedGraphTestCase.java | 125 ------------- .../sca/databinding/impl/MediatorImplTestCase.java | 122 ------------- .../impl/TransformerRegistryImplTestCase.java | 109 ----------- .../impl/XMLDocumentStreamReaderTestCase.java | 57 ------ .../xml/BeanXMLStreamReaderTestCase.java | 192 -------------------- .../sca/databinding/xml/DOM2StAXTestCase.java | 108 ----------- .../sca/databinding/xml/DataPipeTestCase.java | 93 ---------- .../xml/JavaBean2XMLStreamReaderTestCase.java | 144 --------------- .../sca/databinding/xml/Node2StringTestCase.java | 39 ---- .../xml/PushTransformationTestCase.java | 86 --------- .../sca/databinding/xml/StAXHelperTestCase.java | 55 ------ .../databinding/xml/TraxTransformerTestCase.java | 101 ----------- .../xml/XmlTreeStreamReaderTestCase.java | 199 --------------------- 20 files changed, 1985 deletions(-) delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java delete mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java (limited to 'sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache') diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java deleted file mode 100644 index 8c710062ad..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java +++ /dev/null @@ -1,58 +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.extension; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilder; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.impl.DOMHelper; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @version $Rev$ $Date$ - */ -public class DOMHelperTestCase extends TestCase { - private static final QName FOO_NAME = new QName("http://foo", "foo"); - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testDOM() throws Exception { - DocumentBuilder builder = DOMHelper.newDocumentBuilder(); - assertNotNull(builder); - Document document = DOMHelper.newDocument(); - assertNotNull(document); - Element element = DOMHelper.createElement(document, FOO_NAME); - document.appendChild(element); - QName name = DOMHelper.getQName(element); - assertEquals(FOO_NAME, name); - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java deleted file mode 100644 index f9e331fbf3..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java +++ /dev/null @@ -1,86 +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.extension; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.easymock.EasyMock; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * - * @version $Rev$ $Date$ - */ -public class DataBindingExtensionTestCase extends TestCase { - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @SuppressWarnings("unchecked") - public void testExtension() { - DataBinding1 binding1 = new DataBinding1(Node.class); - assertEquals(Node.class.getName(), binding1.getName()); - DataType dt1 = new DataTypeImpl(Element.class, null); - assertTrue(binding1.introspect(dt1, null)); - DataType dt2 = new DataTypeImpl(String.class, null); - assertFalse(binding1.introspect(dt2, null)); - assertNull(binding1.getWrapperHandler()); - - DataBindingExtensionPoint registry = EasyMock.createMock(DataBindingExtensionPoint.class); - registry.addDataBinding(binding1); - EasyMock.expect(registry.getDataBinding(Node.class.getName())).andReturn(binding1); - EasyMock.replay(registry); - - assertNotNull(registry.getDataBinding(Node.class.getName())); - - DataBinding1 binding2 = new DataBinding1("dom", Node.class); - assertEquals("dom", binding2.getName()); - } - - private static class DataBinding1 extends BaseDataBinding { - - /** - * @param baseType - */ - public DataBinding1(Class baseType) { - super(baseType); - } - - /** - * @param name - * @param baseType - */ - public DataBinding1(String name, Class baseType) { - super(name, baseType); - } - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java deleted file mode 100644 index 562c22354c..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java +++ /dev/null @@ -1,124 +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.extension; - -import java.util.HashMap; -import java.util.Map; - -import javax.xml.namespace.NamespaceContext; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; -import org.apache.tuscany.sca.interfacedef.util.TypeInfo; -import org.easymock.EasyMock; - -/** - * - * @version $Rev$ $Date$ - */ -public class SimpleTypeMapperExtensionTestCase extends TestCase { - - private static final Map SAMPLE_VALUES = new HashMap(); - - static { - SAMPLE_VALUES.put("anyURI", "http://www.w3.com"); - SAMPLE_VALUES.put("boolean", new String[] {"true", "false", "1", "0"}); - SAMPLE_VALUES.put("byte", new String[] {"-128", "127"}); - SAMPLE_VALUES.put("date", new String[] {"2004-03-15", "2002-09-24-06:00"}); - SAMPLE_VALUES.put("dateTime", "2003-12-25T08:30:00"); - SAMPLE_VALUES.put("decimal", "3.1415292"); - SAMPLE_VALUES.put("double", new String[] {"3.1415292", "INF", "NaN"}); - SAMPLE_VALUES.put("duration", new String[] {"P8M3DT7H33M2S", "P5Y2M10DT15H"}); - SAMPLE_VALUES.put("float", new String[] {"3.1415292", "INF", "NaN"}); - SAMPLE_VALUES.put("gDay", "---11"); - if (System.getProperty("java.vendor").toUpperCase().contains("SUN") && System.getProperty("java.version").contains("1.5.0") - || - System.getProperty("java.vendor").toUpperCase().contains("APPLE INC.") && System.getProperty("java.version").contains("1.5.0")) { - - // Work around a bug in SUN JDK (including Mac OS JDK) - SAMPLE_VALUES.put("gMonth", "--02--"); - } else { - SAMPLE_VALUES.put("gMonth", "--02"); - } - SAMPLE_VALUES.put("gMonthDay", "--02-14"); - SAMPLE_VALUES.put("gYear", "1999"); - SAMPLE_VALUES.put("gYearMonth", "1972-08"); - SAMPLE_VALUES.put("ID", "id-102"); - SAMPLE_VALUES.put("IDREF", "id-102"); - SAMPLE_VALUES.put("IDREFS", "id-102 id-103 id-100"); - SAMPLE_VALUES.put("int", "77"); - SAMPLE_VALUES.put("integer", "77"); - SAMPLE_VALUES.put("long", "214"); - SAMPLE_VALUES.put("negativeInteger", "-123"); - SAMPLE_VALUES.put("nonNegativeInteger", "2"); - SAMPLE_VALUES.put("nonPositiveInteger", "0"); - SAMPLE_VALUES.put("positiveInteger", "500"); - SAMPLE_VALUES.put("short", "476"); - SAMPLE_VALUES.put("string", "Joeseph"); - SAMPLE_VALUES.put("time", "13:02:00"); - SAMPLE_VALUES.put("base64Binary", "TWFu"); - SAMPLE_VALUES.put("hexBinary", "2CDB5F"); - SAMPLE_VALUES.put("QName", "f:foo"); - SAMPLE_VALUES.put("NOTATION", "f:bar"); - } - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testMap() throws Exception { - SimpleTypeMapperImpl extension = new SimpleTypeMapperImpl(); - TransformationContext context = EasyMock.createMock(TransformationContext.class); - Map metaData = new HashMap(); - EasyMock.expect(context.getMetadata()).andReturn(metaData).anyTimes(); - EasyMock.replay(context); - - NamespaceContext namespaceContext = EasyMock.createMock(NamespaceContext.class); - EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo").anyTimes(); - EasyMock.expect(namespaceContext.getPrefix(EasyMock.eq("http://foo"))).andReturn("f").anyTimes(); - EasyMock.replay(namespaceContext); - context.getMetadata().put(NamespaceContext.class.getName(), namespaceContext); - for (TypeInfo simpleType : SimpleTypeMapperImpl.XSD_SIMPLE_TYPES.values()) { - String name = simpleType.getQName().getLocalPart(); - Object value = SAMPLE_VALUES.get(name); - if (value instanceof String[]) { - for (String s : (String[])value) { - Object obj = extension.toJavaObject(simpleType.getQName(), s, context); - String str = extension.toXMLLiteral(simpleType.getQName(), obj, context); - assertNotNull(str); - // assertTrue("[" + name + "] " + s + " " + str, - // str.contains((String) s)); - } - } else if (value instanceof String) { - Object obj = extension.toJavaObject(simpleType.getQName(), (String)value, context); - String str = extension.toXMLLiteral(simpleType.getQName(), obj, context); - assertNotNull(str); - // assertTrue("[" + name + "] " + value + " " + str, - // str.contains((String) value)); - } - } - } -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java deleted file mode 100644 index 243ac71201..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java +++ /dev/null @@ -1,77 +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.extension; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.Transformer; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.easymock.EasyMock; -import org.w3c.dom.Node; - -/** - * Test case for TransformerExtension - * - * @version $Rev$ $Date$ - */ -public class TransformerExtensionTestCase extends TestCase { - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testExtension() { - MyTransformer transformer = new MyTransformer(); - assertEquals(Node.class.getName(), transformer.getSourceDataBinding()); - assertEquals(XMLStreamReader.class.getName(), transformer.getTargetDataBinding()); - assertEquals(50, transformer.getWeight()); - TransformerExtensionPoint registry = EasyMock.createMock(TransformerExtensionPoint.class); - registry.addTransformer(EasyMock.isA(Transformer.class), EasyMock.eq(true)); - EasyMock - .expect(registry.getTransformer(transformer.getSourceDataBinding(), transformer.getTargetDataBinding())) - .andReturn(transformer); - EasyMock.replay(registry); - registry.addTransformer(transformer, true); - assertSame(transformer, registry.getTransformer(transformer.getSourceDataBinding(), transformer - .getTargetDataBinding())); - } - - private static class MyTransformer extends BaseTransformer { - - @Override - protected Class getSourceType() { - return Node.class; - } - - @Override - protected Class getTargetType() { - return XMLStreamReader.class; - } - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java deleted file mode 100644 index 07ee0b0ca4..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.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.extension; - -import java.math.BigInteger; -import java.util.Calendar; -import java.util.GregorianCalendar; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.impl.XSDDataTypeConverter; - -/** - * - * @version $Rev$ $Date$ - */ -public class XSDDataTypeConverterTestCase extends TestCase { - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testConvert() throws Exception { - XSDDataTypeConverter c = new XSDDataTypeConverter(); - assertEquals("123", c.parseAnySimpleType(c.printAnySimpleType("123"))); - assertEquals(true, c.parseBoolean(c.printBoolean(true))); - assertEquals(false, c.parseBoolean(c.printBoolean(false))); - assertEquals(123.0, c.parseDouble(c.printDouble(123.0))); - assertEquals(123.0f, c.parseFloat(c.printFloat(123.0f))); - assertEquals(64, c.parseByte(c.printByte((byte)64))); - assertEquals(123, c.parseInt(c.printInt(123))); - assertEquals(new BigInteger("123456"), c.parseInteger(c.printInteger(new BigInteger("123456")))); - assertEquals(123456L, c.parseLong(c.printLong(123456L))); - assertEquals((short)123, c.parseShort(c.printShort((short)123))); - - Calendar calendar = new GregorianCalendar(); - String s = c.printDate(calendar); - calendar = c.parseDate(s); - assertEquals(s, c.printDate(calendar)); - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java deleted file mode 100644 index 15b9242340..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java +++ /dev/null @@ -1,97 +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.impl; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.easymock.EasyMock; -import org.xml.sax.ContentHandler; - -/** - * - * @version $Rev$ $Date$ - */ -public class DataBindingRegistryImplTestCase extends TestCase { - private DataBindingExtensionPoint registry; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - registry = new DefaultDataBindingExtensionPoint(); - } - - @SuppressWarnings("unchecked") - public void testRegistry() { - DataBinding db1 = createMock(DataBinding.class); - expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes(); - DataType dataType1 = new DataTypeImpl(ContentHandler.class, ContentHandler.class); - expect(db1.introspect(dataType1, null)).andReturn(true); - expect(db1.introspect(EasyMock.not(EasyMock.same(dataType1)), (Operation) EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db1); - - registry.addDataBinding(db1); - - DataBinding db2 = createMock(DataBinding.class); - expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes(); - DataType dataType2 = new DataTypeImpl(XMLStreamReader.class, XMLStreamReader.class); - expect(db2.introspect(dataType2, null)).andReturn(true); - expect(db2.introspect(EasyMock.not(EasyMock.same(dataType2)), (Operation) EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db2); - - registry.addDataBinding(db2); - - // Lookup by name - String name = db1.getName(); - DataBinding db3 = registry.getDataBinding(name); - assertSame(db1, db3); - - DataType dt = new DataTypeImpl(ContentHandler.class, null); - registry.introspectType(dt, null); - assertEquals(dataType1.getLogical(), ContentHandler.class); - //FIXME does not match with dynamically loaded databindings - //assertTrue(dt.getDataBinding().equalsIgnoreCase("java.lang.Object")); - - registry.removeDataBinding(name); - DataBinding db4 = registry.getDataBinding(name); - assertNull(db4); - - dt = new DataTypeImpl(null, String.class, null); - registry.introspectType(dt, null); - //FIXME does not match with dynamically loaded databindings - //assertEquals("java.lang.Object", dt.getDataBinding()); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java deleted file mode 100644 index 7c882c0285..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java +++ /dev/null @@ -1,49 +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.impl; - -import java.lang.reflect.Method; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.annotation.DataBinding; - -/** - * - * @version $Rev$ $Date$ - */ -public class DataBindingTestCase extends TestCase { - @SuppressWarnings("unused") - public void testDataType() throws Exception { - Class testClass = Test.class; - DataBinding d = testClass.getAnnotation(DataBinding.class); - Assert.assertEquals(d.value(), "sdo"); - - Method method = testClass.getMethod("test", new Class[] {Object.class}); - DataBinding d2 = method.getAnnotation(DataBinding.class); - Assert.assertEquals(d2.value(), "jaxb"); - } - - @DataBinding("sdo") - private static interface Test { - @DataBinding("jaxb") - Object test(Object object); - } -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java deleted file mode 100644 index 053e4f2a59..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java +++ /dev/null @@ -1,125 +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.impl; - -import java.util.Arrays; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Edge; -import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Vertex; - -/** - * - * @version $Rev$ $Date$ - */ -public class DirectedGraphTestCase extends TestCase { - private DirectedGraph graph; - - @Override - protected void setUp() throws Exception { - super.setUp(); - graph = new DirectedGraph(); - } - - public void testGraph() { - graph.addEdge("a", "b", null, 3, true); - graph.addEdge("b", "c", null, 1, true); - // graph.addEdge("a", "c", null, 8, true); - graph.addEdge("a", "d", null, 3, true); - graph.addEdge("b", "d", null, 2, true); - graph.addEdge("d", "c", null, 3, true); - graph.addEdge("c", "b", null, 1, true); - graph.addEdge("c", "d", null, 2, true); - graph.addEdge("d", "b", null, 1, true); - graph.addEdge("a", "e", null, 8, true); - graph.addEdge("c", "c", null, 2, true); - graph.addEdge("f", "g", null, 2, false); - graph.addEdge("f", "h", null, 8, true); - graph.addEdge("g", "j", null, 2, false); - graph.addEdge("j", "i", null, 2, true); - graph.addEdge("h", "i", null, 8, true); - - Vertex vertex = graph.getVertex("a"); - Assert.assertNotNull(vertex); - Assert.assertEquals(vertex.getValue(), "a"); - - Assert.assertNull(graph.getVertex("1")); - - Edge edge = graph.getEdge("a", "b"); - Assert.assertNotNull(edge); - Assert.assertEquals(edge.getWeight(), 3); - - edge = graph.getEdge("b", "a"); - Assert.assertNull(edge); - - DirectedGraph.Path path = graph.getShortestPath("a", "c"); - - List.Edge> edges = path.getEdges(); - Assert.assertEquals(edges.size(), 2); - Assert.assertEquals(edges.get(0), graph.getEdge("a", "b")); - Assert.assertEquals(edges.get(1), graph.getEdge("b", "c")); - - Assert.assertEquals(path.getWeight(), 4); - - DirectedGraph.Path path2 = graph.getShortestPath("b", "e"); - Assert.assertNull(path2); - - DirectedGraph.Path path3 = graph.getShortestPath("a", "a"); - Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty()); - - DirectedGraph.Path path4 = graph.getShortestPath("c", "c"); - Assert.assertTrue(path4.getWeight() == 2 && path4.getEdges().size() == 1); - - DirectedGraph.Path path5 = graph.getShortestPath("f", "i"); - Assert.assertTrue(path5.getWeight() == 16 && path5.getEdges().size() == 2); - - } - - public void testSort() { - graph.addEdge("a", "b"); - graph.addEdge("a", "c"); - graph.addEdge("c", "d"); - graph.addEdge("b", "c"); - List order = graph.topologicalSort(true); - assertEquals(Arrays.asList("a", "b", "c", "d"), order); - assertTrue(!graph.getVertices().isEmpty()); - - graph.addEdge("d", "a"); - try { - order = graph.topologicalSort(true); - assertTrue("Should have failed", false); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - - graph.removeEdge("d", "a"); - order = graph.topologicalSort(false); - assertEquals(Arrays.asList("a", "b", "c", "d"), order); - assertTrue(graph.getVertices().isEmpty()); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java deleted file mode 100644 index 6cc8868397..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java +++ /dev/null @@ -1,122 +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.impl; - -import java.io.StringWriter; -import java.io.Writer; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.xml.Node2String; -import org.apache.tuscany.sca.databinding.xml.Node2Writer; -import org.apache.tuscany.sca.databinding.xml.SAX2DOMPipe; -import org.apache.tuscany.sca.databinding.xml.String2SAX; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Test case for MediatorImpl - * - * @version $Rev$ $Date$ - */ -public class MediatorImplTestCase extends TestCase { - private static final String IPO_XML = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + "PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + "99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - private MediatorImpl mediator; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - DataBindingExtensionPoint dataBindingRegistry = new DefaultDataBindingExtensionPoint(); - TransformerExtensionPoint registry = new DefaultTransformerExtensionPoint(); - - registry.addTransformer(new String2SAX(), true); - registry.addTransformer(new SAX2DOMPipe(), true); - registry.addTransformer(new Node2String(), true); - registry.addTransformer(new Node2Writer(), true); - - mediator = new MediatorImpl(dataBindingRegistry, registry); - } - - private TransformationContext createTransformationContext(Class sourceType, Class targetType) { - TransformationContext context = new TransformationContextImpl(); - DataType sourceDataType = new DataTypeImpl(sourceType.getName(), sourceType, sourceType); - DataType targetDataType = new DataTypeImpl(targetType.getName(), targetType, targetType); - context.setSourceDataType(sourceDataType); - context.setTargetDataType(targetDataType); - return context; - } - - public void testTransform1() { - TransformationContext context = createTransformationContext(String.class, Node.class); - Object node = - mediator.mediate(IPO_XML, context.getSourceDataType(), context.getTargetDataType(), null); - Assert.assertTrue(node instanceof Document); - Element root = ((Document)node).getDocumentElement(); - Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO"); - Assert.assertEquals(root.getLocalName(), "purchaseOrder"); - } - - public void testTransform2() { - TransformationContext context = createTransformationContext(String.class, Writer.class); - Writer writer = new StringWriter(); - mediator.mediate(IPO_XML, writer, context.getSourceDataType(), context.getTargetDataType(), null); - String str = writer.toString(); - Assert.assertTrue(str != null && str.indexOf("1999-12-05") != -1); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java deleted file mode 100644 index 31c3fd4f00..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java +++ /dev/null @@ -1,109 +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.impl; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.Transformer; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; - -/** - * - * @version $Rev$ $Date$ - */ -public class TransformerRegistryImplTestCase extends TestCase { - private TransformerExtensionPoint registry; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - registry = new DefaultTransformerExtensionPoint(); - } - - public void testRegisterTransformer1() { - Transformer transformer = createMock(Transformer.class); - registry.addTransformer("a", "b", 10, transformer, true); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertSame(t, transformer); - } - - public void testRegisterTransformerTransformer() { - Transformer transformer = createMock(Transformer.class); - expect(transformer.getSourceDataBinding()).andReturn("a"); - expect(transformer.getTargetDataBinding()).andReturn("b"); - expect(transformer.getWeight()).andReturn(10); - replay(transformer); - registry.addTransformer(transformer, true); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertSame(t, transformer); - } - - public void testUnregisterTransformer() { - Transformer transformer = createMock(Transformer.class); - registry.addTransformer("a", "b", 10, transformer, true); - boolean result = registry.removeTransformer("a", "b"); - Assert.assertTrue(result); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertNull(t); - } - - public void testGetTransformerChain() { - Transformer t1 = createMock(Transformer.class); - expect(t1.getSourceDataBinding()).andReturn("a"); - expect(t1.getTargetDataBinding()).andReturn("b"); - expect(t1.getWeight()).andReturn(10); - replay(t1); - Transformer t2 = createMock(Transformer.class); - expect(t2.getSourceDataBinding()).andReturn("b"); - expect(t2.getTargetDataBinding()).andReturn("c"); - expect(t2.getWeight()).andReturn(20); - replay(t2); - - Transformer t3 = createMock(Transformer.class); - expect(t3.getSourceDataBinding()).andReturn("a"); - expect(t3.getTargetDataBinding()).andReturn("c"); - expect(t3.getWeight()).andReturn(120); - replay(t3); - - registry.addTransformer(t1, true); - registry.addTransformer(t2, true); - registry.addTransformer(t3, true); - - List l1 = registry.getTransformerChain("a", "b"); - Assert.assertTrue(l1.size() == 1 && l1.get(0) == t1); - List l2 = registry.getTransformerChain("a", "c"); - Assert.assertTrue(l2.size() == 1 && l2.get(0) == t3); - List l3 = registry.getTransformerChain("a", "d"); - Assert.assertNull(l3); - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java deleted file mode 100644 index dd3d000798..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java +++ /dev/null @@ -1,57 +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.impl; - -import java.io.StringReader; - -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 org.apache.tuscany.sca.databinding.xml.XMLDocumentStreamReader; -import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; - -/** - * @version $Rev$ $Date$ - */ -public class XMLDocumentStreamReaderTestCase { - private static final String xml = "E4"; - - @org.junit.Test - public void testReader() throws Exception { - XMLInputFactory factory = XMLInputFactory.newInstance(); - XMLStreamReader r1 = factory.createXMLStreamReader(new StringReader(xml)); - XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1); - XMLStreamReader2String t1 = new XMLStreamReader2String(); - String result = t1.transform(r2, null); - System.out.println(result); - XMLStreamReader r3 = factory.createXMLStreamReader(new StringReader(xml)); - r3.nextTag(); - r3.nextTag(); - Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType()); - Assert.assertEquals(new QName(null, "e2"), r3.getName()); - XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3); - result = t1.transform(r4, null); - System.out.println(result); - } -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java deleted file mode 100644 index bdc9690285..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java +++ /dev/null @@ -1,192 +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.xml; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.custommonkey.xmlunit.Diff; - -/** - * - * @version $Rev$ $Date$ - */ -public class BeanXMLStreamReaderTestCase extends TestCase { - private static final String XML_RESULT = - "" + "" - + "123Name1" - + "Item1Item2" - + "key1value1" - + "key2value2" - + "" - + "ABC"; - - // The map entries can come in a different order - private static final String XML_RESULT1 = - "" + "" - + "123Name1" - + "Item1Item2" - + "key2value2" - + "key1value1" - + "" - + "ABC"; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() throws Exception { - MyBean bean = new MyBean(); - bean.str = "ABC"; - bean.i = 1; - bean.arr = new long[] {1, 2, 3}; - bean.bean = new AnotherBean(); - bean.bean.setName("Name"); - bean.list.add("Item1"); - bean.list.add("Item2"); - bean.map.put("key1", "value1"); - bean.map.put("key2", "value2"); - XMLStreamReader reader = new BeanXMLStreamReaderImpl(null, bean); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - Diff diff = new Diff(XML_RESULT, xml); - Diff diff1 = new Diff(XML_RESULT1, xml); - assertTrue(diff.similar() || diff1.similar()); - } - - private static class MyBean { - private long arr[]; - private String str; - private int i; - private String nil; - private List list = new ArrayList(); - private AnotherBean bean; - private Map map = new HashMap(); - - /** - * @return the i - */ - public int getI() { - return i; - } - - /** - * @param i the i to set - */ - public void setI(int i) { - this.i = i; - } - - /** - * @return the arr - */ - public long[] getArr() { - return arr; - } - - /** - * @param arr the arr to set - */ - public void setArr(long[] arr) { - this.arr = arr; - } - - /** - * @return the str - */ - public String getStr() { - return str; - } - - /** - * @param str the str to set - */ - public void setStr(String str) { - this.str = str; - } - - /** - * @return the bean - */ - public AnotherBean getBean() { - return bean; - } - - /** - * @param bean the bean to set - */ - public void setBean(AnotherBean bean) { - this.bean = bean; - } - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } - - public String getNil() { - return nil; - } - - public void setNil(String nil) { - this.nil = nil; - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - this.map = map; - } - - } - - private static class AnotherBean { - private String name; - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java deleted file mode 100644 index 9e9dabcea7..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java +++ /dev/null @@ -1,108 +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.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.custommonkey.xmlunit.XMLAssert; -import org.w3c.dom.Node; - -/** - * - * @version $Rev$ $Date$ - */ -public class DOM2StAXTestCase extends TestCase { - private static final String IPO_XML = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - private static final String CRAZY_XML = - "" + "E4"; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() throws Exception { - String2Node t1 = new String2Node(); - Node node = t1.transform(IPO_XML, null); - Node2XMLStreamReader t2 = new Node2XMLStreamReader(); - XMLStreamReader reader = t2.transform(node, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - XMLAssert.assertXMLEqual(IPO_XML, xml); - // assertTrue(xml != null && xml.indexOf("1999-12-05") != -1); - } - - public void testTransformation2() throws Exception { - String2Node t1 = new String2Node(); - Node node = t1.transform(CRAZY_XML, null); - Node2XMLStreamReader t2 = new Node2XMLStreamReader(); - XMLStreamReader reader = t2.transform(node, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - // System.out.println(xml); - XMLAssert.assertXMLEqual(CRAZY_XML, xml); - assertTrue(xml.contains("1999-12-05") != -1); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java deleted file mode 100644 index f3b37c86db..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java +++ /dev/null @@ -1,93 +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.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.DataPipe; -import org.apache.tuscany.sca.databinding.DataPipeTransformer; -import org.apache.tuscany.sca.databinding.impl.DOMHelper; -import org.apache.tuscany.sca.databinding.impl.PipedTransformer; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Test case for DataPipe - * - * @version $Rev$ $Date$ - */ -public class DataPipeTestCase extends TestCase { - - public final void testStreamPipe() throws IOException { - byte[] bytes = new byte[] {1, 2, 3}; - DataPipeTransformer pipe = new StreamDataPipe(); - DataPipe dataPipe = pipe.newInstance(); - OutputStream os = dataPipe.getSink(); - os.write(bytes); - byte[] newBytes = new byte[16]; - int count = dataPipe.getResult().read(newBytes); - Assert.assertEquals(3, count); - for (int i = 0; i < bytes.length; i++) { - Assert.assertEquals(bytes[i], newBytes[i]); - } - } - - public final void testWriter2ReaderPipe() throws IOException { - String str = "ABC"; - Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe(); - Assert.assertSame(Writer.class, pipe.getSourceType()); - Assert.assertSame(Reader.class, pipe.getTargetType()); - DataPipe dataPipe = pipe.newInstance(); - dataPipe.getSink().write(str); - char[] buf = new char[16]; - int count = dataPipe.getResult().read(buf); - Assert.assertEquals(3, count); - for (int i = 0; i < str.length(); i++) { - Assert.assertEquals(str.charAt(i), buf[i]); - } - } - - public final void testPiped() throws Exception { - Node2Writer node2Writer = new Node2Writer(); - Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe(); - PipedTransformer transformer = - new PipedTransformer(node2Writer, pipe); - Document document = DOMHelper.newDocument(); - Element element = document.createElementNS("http://ns1", "root"); - document.appendChild(element); - Reader reader = transformer.transform(document, null); - Assert.assertEquals(transformer.getWeight(), node2Writer.getWeight() + pipe.getWeight()); - Assert.assertEquals(transformer.getSourceDataBinding(), node2Writer.getSourceDataBinding()); - Assert.assertEquals(transformer.getTargetDataBinding(), pipe.getTargetDataBinding()); - char[] buf = new char[120]; - int count = reader.read(buf); - String xml = new String(buf, 0, count); - Assert.assertTrue(xml.contains("")); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java deleted file mode 100644 index 3a287a5bb7..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java +++ /dev/null @@ -1,144 +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.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.javabeans.JavaBean2XMLStreamReaderTransformer; -import org.custommonkey.xmlunit.XMLAssert; - -/** - * - * @version $Rev$ $Date$ - */ -public class JavaBean2XMLStreamReaderTestCase extends TestCase { - private static final String XML_RESULT = - "" - + "" - + "123Name1ABC" - + ""; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() throws Exception { - JavaBean2XMLStreamReaderTransformer t2 = new JavaBean2XMLStreamReaderTransformer(); - MyBean bean = new MyBean(); - bean.str = "ABC"; - bean.i = 1; - bean.arr = new long[] {1, 2, 3}; - bean.bean = new AnotherBean(); - bean.bean.setName("Name"); - XMLStreamReader reader = t2.transform(bean, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - XMLAssert.assertXMLEqual(XML_RESULT, xml); - - } - - private static class MyBean { - private String str; - private int i; - private long arr[]; - private AnotherBean bean; - - /** - * @return the arr - */ - public long[] getArr() { - return arr; - } - - /** - * @param arr the arr to set - */ - public void setArr(long[] arr) { - this.arr = arr; - } - - /** - * @return the i - */ - public int getI() { - return i; - } - - /** - * @param i the i to set - */ - public void setI(int i) { - this.i = i; - } - - /** - * @return the str - */ - public String getStr() { - return str; - } - - /** - * @param str the str to set - */ - public void setStr(String str) { - this.str = str; - } - - /** - * @return the bean - */ - public AnotherBean getBean() { - return bean; - } - - /** - * @param bean the bean to set - */ - public void setBean(AnotherBean bean) { - this.bean = bean; - } - - } - - private static class AnotherBean { - private String name; - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java deleted file mode 100644 index cc1f9375c8..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java +++ /dev/null @@ -1,39 +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.xml; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.impl.DOMHelper; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @version $Rev$ $Date$ - */ -public class Node2StringTestCase extends TestCase { - public void testTransformation() throws Exception { - Document document = DOMHelper.newDocument(); - Element element = document.createElementNS("http://ns1", "test"); - document.appendChild(element); - - new Node2String().transform(document, null); - } -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java deleted file mode 100644 index 5ae0616577..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java +++ /dev/null @@ -1,86 +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.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sca.databinding.impl.PipedTransformer; -import org.w3c.dom.Node; -import org.xml.sax.ContentHandler; - -/** - * - * @version $Rev$ $Date$ - */ -public class PushTransformationTestCase extends TestCase { - private static final String IPO_XML = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() { - String2XMLStreamReader t1 = new String2XMLStreamReader(); - XMLStreamReader reader = t1.transform(IPO_XML, null); - XMLStreamReader2SAX t2 = new XMLStreamReader2SAX(); - PipedTransformer t3 = - new PipedTransformer(t2, new SAX2DOMPipe()); - Node node = t3.transform(reader, null); - Assert.assertNotNull(node); - Node2String t4 = new Node2String(); - String xml = t4.transform(node, null); - Assert.assertTrue(xml != null && xml.indexOf("1999-12-05") != -1); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java deleted file mode 100644 index 9ca490f2d8..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.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.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.custommonkey.xmlunit.XMLAssert; - -/** - * Test Case for StAXHelper - * - * @version $Rev$ $Date$ - */ -public class StAXHelperTestCase extends TestCase { - private static final String XML = - "" - + "" - + ""; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testHelper() throws Exception { - XMLStreamReader reader = StAXHelper.createXMLStreamReader(XML); - String xml = StAXHelper.save(reader); - XMLAssert.assertXMLEqual(XML, xml); - reader = StAXHelper.createXMLStreamReader(xml); - assertNotNull(reader); - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java deleted file mode 100644 index ff6f8c1406..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java +++ /dev/null @@ -1,101 +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.xml; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URL; - -import junit.framework.TestCase; - -import org.w3c.dom.Node; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * - * @version $Rev$ $Date$ - */ -public class TraxTransformerTestCase extends TestCase { - private URL url; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - url = getClass().getResource("foo.xml"); - } - - public void testTransformDOM() throws IOException { - InputStream is = url.openStream(); - InputStream2Node t1 = new InputStream2Node(); - Node node = t1.transform(is, null); - is.close(); - Writer writer = new StringWriter(); - Node2Writer t2 = new Node2Writer(); - t2.transform(node, writer, null); - String str = writer.toString(); - StringReader reader = new StringReader(str); - Reader2Node t3 = new Reader2Node(); - node = t3.transform(reader, null); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - Node2OutputStream t4 = new Node2OutputStream(); - t4.transform(node, os, null); - InputSource inputSource = new InputSource(new ByteArrayInputStream(os.toByteArray())); - InputSource2Node t5 = new InputSource2Node(); - node = t5.transform(inputSource, null); - } - - public void testTransformSAX() throws IOException { - MyContentHandler handler = new MyContentHandler(); - InputStream is = url.openStream(); - InputStream2SAX t1 = new InputStream2SAX(); - t1.transform(is, handler, null); - is.close(); - - String xml = "bar"; - - InputSource inputSource = new InputSource(new StringReader(xml)); - InputSource2SAX t2 = new InputSource2SAX(); - MyContentHandler handler2 = new MyContentHandler(); - t2.transform(inputSource, handler2, null); - - } - - private static class MyContentHandler extends DefaultHandler { - - @Override - public void startElement(String namespaceURI, String localName, String qName, Attributes atts) - throws SAXException { - super.startElement(namespaceURI, localName, qName, atts); - } - - } - -} diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java deleted file mode 100644 index 0463e7d9f5..0000000000 --- a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java +++ /dev/null @@ -1,199 +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.xml; - -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; - -import org.custommonkey.xmlunit.XMLAssert; -import org.junit.Before; -import org.junit.Test; - -/** - * @version $Rev$ $Date$ - */ -public class XmlTreeStreamReaderTestCase { - private static final String IPO_XML = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - private static final String XML_RESULT = - "" + "" - + "MyText" - + "" - + " " - + " " - + "Helen Zoe 47 Eden Street " - + "Cambridge CB1 1JR " - + " Robert Smith " - + "8 Oak Avenue Old Town PA " - + "95819 " - + "Lapis necklace 1 " - + "99.95 Want this for the holidays " - + "1999-12-05 "; - private XmlNodeImpl root; - - @Before - public void setUp() throws Exception { - root = new XmlNodeImpl(); - root.name = new QName("http://ns", "e1", "p1"); - - XmlNodeImpl e11 = new XmlNodeImpl(); - e11.name = new QName("http://ns1", "e11", "p2"); - - XmlNodeImpl e12 = new XmlNodeImpl(); - e12.name = new QName("http://ns", "e12"); - - root.children.add(e11); - root.children.add(e12); - - XmlNodeImpl e121 = new XmlNodeImpl(); - e121.name = new QName("http://ns", "e121"); - e12.children.add(e121); - - XmlNodeImpl e111 = new XmlNodeImpl(); - e111.value = "MyText"; - e11.children.add(e111); - - XmlNodeImpl e13 = new XmlNodeImpl(); - e13.value = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); - root.children.add(e13); - - } - - @Test - public void testIterator() { - List elements = new ArrayList(); - XmlNodeIterator i = new XmlNodeIterator(root); - for (; i.hasNext();) { - XmlNode e = i.next(); - elements.add(e.getName()); - } - // System.out.println(elements); - QName[] names = - {new QName("http://ns", "e1"), new QName("http://ns1", "e11"), null, null, new QName("http://ns1", "e11"), - new QName("http://ns", "e12"), new QName("http://ns", "e121"), new QName("http://ns", "e121"), - new QName("http://ns", "e12"), null, null, new QName("http://ns", "e1")}; - Assert.assertEquals(Arrays.asList(names), elements); - } - - @Test - public void testReader() throws Exception { - XmlTreeStreamReaderImpl reader = new XmlTreeStreamReaderImpl(root); - XMLStreamReader2String t = new XMLStreamReader2String(); - String xml = t.transform(reader, null); - XMLAssert.assertXMLEqual(XML_RESULT, xml); - } - - private static class XmlNodeImpl implements XmlNode { - private List children = new ArrayList(); - private List attrs = new ArrayList(); - private Map namespaces = new HashMap(); - private QName name; - private Object value = "123"; - - /** - * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes() - */ - public List attributes() { - return attrs; - } - - /** - * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children() - */ - public Iterator children() { - return children.iterator(); - } - - /** - * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName() - */ - public QName getName() { - return name; - } - - /** - * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue() - */ - public T getValue() { - return (T)value; - } - - /** - * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces() - */ - public Map namespaces() { - return namespaces; - } - - @Override - public String toString() { - return String.valueOf(name); - } - - public Type getType() { - if (value instanceof XMLStreamReader) { - return Type.READER; - } - return name == null ? Type.CHARACTERS : Type.ELEMENT; - } - - } -} -- cgit v1.2.3