diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-02 02:04:03 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-02 02:04:03 +0000 |
commit | 62bbc88103ff9b26a2b88ccffeda0dba2294aa66 (patch) | |
tree | 74425bfe0484dfaf38f0c21eed8159fe12b68695 /branches/sca-java-1.x/modules/binding-http-new/src/test/java/org | |
parent | 88389b44557c4465d011d9a7cd69421ed8857686 (diff) |
TUSCANY-2968 - Renaming new binding.http module to avoid confusion with the oasis draft, as we are not really implementing the whole spec but just following the wireFormat and operationSelector options implemented in binding.jms
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@770880 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-http-new/src/test/java/org')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-http-new/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/binding-http-new/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java b/branches/sca-java-1.x/modules/binding-http-new/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java new file mode 100644 index 0000000000..b19935c1e0 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-http-new/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java @@ -0,0 +1,109 @@ +/* + * 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.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +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 = "<ns1:binding.http xmlns:ns1=\"http://tuscany.apache.org/xmlns/sca/1.0\" name=\"name\" uri=\"uri\" />"; + + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + + private static Monitor monitor; + + private static ExtensibleStAXArtifactProcessor staxProcessor; + private static HTTPBindingProcessor httpBindingProcessor; + + @BeforeClass + public static void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + + outputFactory = XMLOutputFactory.newInstance(); + outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + + 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); + } + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + + httpBindingProcessor = new HTTPBindingProcessor(extensionPoints, staxProcessor, null, 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()); + } +} |