diff options
Diffstat (limited to 'sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java')
-rw-r--r-- | sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java b/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java deleted file mode 100644 index a120b313ff..0000000000 --- a/sandbox/ant/sca/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java +++ /dev/null @@ -1,95 +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 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.junit.Assert; -import org.junit.Test; -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 { - - @Test - public final void testStreamPipe() throws IOException { - byte[] bytes = new byte[] {1, 2, 3}; - DataPipeTransformer<OutputStream, InputStream> pipe = new StreamDataPipe(); - DataPipe<OutputStream, InputStream> 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]); - } - } - - @Test - 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<Writer, Reader> 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]); - } - } - - @Test - public final void testPiped() throws Exception { - Node2Writer node2Writer = new Node2Writer(); - Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe(); - PipedTransformer<Node, Writer, Reader> transformer = - new PipedTransformer<Node, Writer, Reader>(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("<root xmlns=\"http://ns1\"/>")); - } - -} |