diff options
Diffstat (limited to 'tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl')
4 files changed, 0 insertions, 356 deletions
diff --git a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java b/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java deleted file mode 100644 index c5d6dbbcc1..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java +++ /dev/null @@ -1,48 +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.junit.Assert.assertEquals; - -import java.lang.reflect.Method; - -import org.apache.tuscany.sca.databinding.annotation.DataBinding; - -/** - * - * @version $Rev$ $Date$ - */ -public class DataBindingTestCase { - @org.junit.Test - public void testDataType() throws Exception { - Class<Test> testClass = Test.class; - DataBinding d = testClass.getAnnotation(DataBinding.class); - assertEquals(d.value(), "sdo"); - - Method method = testClass.getMethod("test", new Class[] {Object.class}); - DataBinding d2 = method.getAnnotation(DataBinding.class); - assertEquals(d2.value(), "jaxb"); - } - - @DataBinding("sdo") - private static interface Test { - @DataBinding("jaxb") - Object test(Object object); - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java b/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java deleted file mode 100644 index d48711cd64..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java +++ /dev/null @@ -1,123 +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.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Edge; -import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Vertex; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * - * @version $Rev$ $Date$ - */ -public class DirectedGraphTestCase { - private DirectedGraph<String, Object> graph; - - @Before - public void setUp() throws Exception { - graph = new DirectedGraph<String, Object>(); - } - - @Test - 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<String, Object>.Path path = graph.getShortestPath("a", "c"); - - List<DirectedGraph<String, Object>.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<String, Object>.Path path2 = graph.getShortestPath("b", "e"); - Assert.assertNull(path2); - - DirectedGraph<String, Object>.Path path3 = graph.getShortestPath("a", "a"); - Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty()); - - DirectedGraph<String, Object>.Path path4 = graph.getShortestPath("c", "c"); - Assert.assertTrue(path4.getWeight() == 2 && path4.getEdges().size() == 1); - - DirectedGraph<String, Object>.Path path5 = graph.getShortestPath("f", "i"); - Assert.assertTrue(path5.getWeight() == 16 && path5.getEdges().size() == 2); - - } - - @Test - public void testSort() { - graph.addEdge("a", "b"); - graph.addEdge("a", "c"); - graph.addEdge("c", "d"); - graph.addEdge("b", "c"); - List<String> 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()); - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java b/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java deleted file mode 100644 index a74a8e5550..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.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.io.StringWriter; -import java.io.Writer; - -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.junit.Assert; -import org.junit.Before; -import org.junit.Test; -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 { - private static final String IPO_XML = - "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + "<state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + "<USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</ipo:purchaseOrder>"; - - private MediatorImpl mediator; - - @Before - public void setUp() throws Exception { - ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry(); - DataBindingExtensionPoint dataBindingRegistry = new DefaultDataBindingExtensionPoint(extensionPointRegistry); - TransformerExtensionPoint registry = new DefaultTransformerExtensionPoint(extensionPointRegistry); - - registry.addTransformer(new String2SAX(), true); - registry.addTransformer(new SAX2DOMPipe(extensionPointRegistry), 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<Class>(sourceType.getName(), sourceType, sourceType); - DataType targetDataType = new DataTypeImpl<Class>(targetType.getName(), targetType, targetType); - context.setSourceDataType(sourceDataType); - context.setTargetDataType(targetDataType); - return context; - } - - @Test - 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"); - } - - @Test - 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("<shipDate>1999-12-05</shipDate>") != -1); - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java b/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java deleted file mode 100644 index e240592adf..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java +++ /dev/null @@ -1,60 +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.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.common.xml.stax.StAXHelper; -import org.apache.tuscany.sca.common.xml.stax.reader.XMLDocumentStreamReader; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; -import org.junit.Assert; - -/** - * @version $Rev$ $Date$ - */ -public class XMLDocumentStreamReaderTestCase { - private static final String xml = "<e1><e2 a2=\"a2\"><e4>E4</e4></e2><e3 a3=\"a3\"/></e1>"; - - @org.junit.Test - public void testReader() throws Exception { - ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry(); - - StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry); - XMLStreamReader r1 = helper.createXMLStreamReader(new StringReader(xml)); - XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1); - XMLStreamReader2String t1 = new XMLStreamReader2String(extensionPointRegistry); - String result = t1.transform(r2, null); - System.out.println(result); - XMLStreamReader r3 = helper.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); - } -} |