diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-23 03:57:22 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-23 03:57:22 +0000 |
commit | 1b79cd65550b77d4c9abac3cede358a4da7dff65 (patch) | |
tree | 87cbe5d560cb1ce20638b107a93ae11ac45b16b4 /branches/sca-java-1.x/modules/binding-http-oasis/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java | |
parent | d8a388616db9870fa65219074942609670d2625e (diff) |
TUSCANY-2968 - Adding new binding processor and making necessary adjustment to move to spec namespace
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@767777 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-http-oasis/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/binding-http-oasis/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java b/branches/sca-java-1.x/modules/binding-http-oasis/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java new file mode 100644 index 0000000000..46025e0311 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-http-oasis/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.binding.http.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @version $Rev$ $Date$ + */ +public class HTTPBindingProcessorTestCase { + + private static final String XML = "<binding.http name=\"name\" uri=\"uri\" />"; + + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + + private static Monitor monitor; + + private static HTTPBindingProcessor httpBindingProcessor; + + @BeforeClass + public static void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + httpBindingProcessor = new HTTPBindingProcessor(modelFactories, monitor); + } + + + /** + * Read and Write a composite using the HTTP Binding + * + * @throws Exception + */ + @Test + public void testReadWriteCompositeWithHTTPBinding() throws Exception { + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + reader.next(); + + HTTPBinding httpBinding = (HTTPBinding) httpBindingProcessor.read(reader); + assertNotNull(httpBinding); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + writer.setDefaultNamespace("http://www.osoa.org/xmlns/sca/1.0"); + httpBindingProcessor.write(httpBinding, writer); + writer.writeEndDocument(); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + } +} |