diff options
Diffstat (limited to 'sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension')
5 files changed, 0 insertions, 394 deletions
diff --git a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java deleted file mode 100644 index 5e57f64b5f..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java +++ /dev/null @@ -1,53 +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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilder; - -import org.apache.tuscany.sca.databinding.impl.DOMHelper; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @version $Rev$ $Date$ - */ -public class DOMHelperTestCase { - private static final QName FOO_NAME = new QName("http://foo", "foo"); - - @Test - 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/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java deleted file mode 100644 index 7d14cd9dd1..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java +++ /dev/null @@ -1,82 +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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; -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.junit.Test; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * - * @version $Rev$ $Date$ - */ -public class DataBindingExtensionTestCase { - - @Test - @SuppressWarnings("unchecked") - public void testExtension() { - DataBinding1 binding1 = new DataBinding1(Node.class); - assertEquals(Node.class.getName(), binding1.getName()); - DataType dt1 = new DataTypeImpl<Class>(Element.class, null); - assertTrue(binding1.introspect(dt1, null)); - DataType dt2 = new DataTypeImpl<Class>(String.class, null); - assertFalse(binding1.introspect(dt2, null)); - assertNull(binding1.getWrapperHandler()); - - DataBindingExtensionPoint registry = new DefaultDataBindingExtensionPoint(); - registry.addDataBinding(binding1); - - 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/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java.fixme b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java.fixme deleted file mode 100644 index 562c22354c..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java.fixme +++ /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<String, Object> SAMPLE_VALUES = new HashMap<String, Object>(); - - 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<String, Object> metaData = new HashMap<String, Object>(); - 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/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java.fixme b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java.fixme deleted file mode 100644 index 243ac71201..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java.fixme +++ /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<Node, XMLStreamReader> { - - @Override - protected Class<Node> getSourceType() { - return Node.class; - } - - @Override - protected Class<XMLStreamReader> getTargetType() { - return XMLStreamReader.class; - } - - } - -} diff --git a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java deleted file mode 100644 index a337dc113c..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.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 static org.junit.Assert.assertEquals; - -import java.math.BigInteger; -import java.util.Calendar; -import java.util.GregorianCalendar; - -import org.apache.tuscany.sca.databinding.impl.XSDDataTypeConverter; -import org.junit.Test; - -/** - * - * @version $Rev$ $Date$ - */ -public class XSDDataTypeConverterTestCase { - - @Test - 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)), 0); - assertEquals(123.0f, c.parseFloat(c.printFloat(123.0f)), 0); - 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)); - - } - -} |