Author: lresende
Date: Sun Apr 25 17:51:44 2010
New Revision: 937845
URL: http://svn.apache.org/viewvc?rev=937845&view=rev
Log:
Initial support for json wire format model
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
(with props)
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
(with props)
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
(with props)
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
(with props)
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory
- copied, changed from r937844,
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
(with props)
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
tuscany/sca-java-2.x/trunk/modules/binding-rest/pom.xml
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF?rev=937845&r1=937844&r2=937845&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF Sun
Apr 25 17:51:44 2010
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
-Export-Package:
org.apache.tuscany.sca.binding.rest;version="2.0.0";uses:="org.apache.tuscany.sca.assembly,javax.xml.namespace,javax.servlet.http"
+Export-Package:
org.apache.tuscany.sca.binding.rest;version="2.0.0";uses:="org.apache.tuscany.sca.assembly,javax.xml.namespace,javax.servlet.http",
+ org.apache.tuscany.sca.binding.rest.wireformat.json;version="2.0.0"
Bundle-Name: Apache Tuscany SCA REST Binding Model
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 2.0.0
Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest/pom.xml
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/pom.xml?rev=937845&r1=937844&r2=937845&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest/pom.xml Sun Apr 25 17:51:44
2010
@@ -42,6 +42,13 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java?rev=937845&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
Sun Apr 25 17:51:44 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.rest.wireformat.json;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.WireFormat;
+
+/**
+ * JSON Wireformat model for REST Binding
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RESTWireFormatJSON extends WireFormat {
+
+ /**
+ * QName representing the JSON Wireformat for REST Binding
+ */
+ public static final QName REST_WIREFORMAT_JSON_QNAME = new
QName(SCA11_TUSCANY_NS, "wireFormat.jsonrpc");
+
+ /**
+ * Return the QName identifying the wire format
+ * @return the QName identifying the wire format
+ */
+ QName getSchemaName();
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSON.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java?rev=937845&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
Sun Apr 25 17:51:44 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.rest.wireformat.json;
+
+/**
+ * JSON Wireformat factory for REST Binding
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RESTWireFormatJSONFactory {
+
+ /**
+ * Create a new JSON wireformat for REST Binding
+ * @return the new JSON wire format
+ */
+ RESTWireFormatJSON createRESTWireFormatJSON();
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/RESTWireFormatJSONFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java?rev=937845&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
Sun Apr 25 17:51:44 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.rest.wireformat.json.impl;
+
+import org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSON;
+import
org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory;
+
+/**
+ * JSON Wireformat factory implementation for REST Binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class RESTWireFormatJSONFactoryImpl implements
RESTWireFormatJSONFactory {
+
+ public RESTWireFormatJSON createRESTWireFormatJSON() {
+ return new RESTWireFormatJSONImpl();
+ }
+
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java?rev=937845&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
Sun Apr 25 17:51:44 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.rest.wireformat.json.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSON;
+
+
+/**
+ * JSON Wireformat implementation for REST Binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class RESTWireFormatJSONImpl implements RESTWireFormatJSON {
+
+ public QName getSchemaName() {
+ return RESTWireFormatJSON.REST_WIREFORMAT_JSON_QNAME;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // no op
+ }
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java?rev=937845&r1=937844&r2=937845&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
Sun Apr 25 17:51:44 2010
@@ -114,19 +114,29 @@ public class RESTBindingProcessor extend
return httpBinding;
}
- public void write(RESTBinding httpBinding, XMLStreamWriter writer,
ProcessorContext context) throws ContributionWriteException, XMLStreamException
{
+ public void write(RESTBinding restBinding, XMLStreamWriter writer,
ProcessorContext context) throws ContributionWriteException, XMLStreamException
{
//writer.writeStartElement(Constants.SCA10_NS, BINDING_HTTP);
writeStart(writer, RESTBinding.TYPE.getNamespaceURI(),
RESTBinding.TYPE.getLocalPart());
// Write binding name
- if (httpBinding.getName() != null) {
- writer.writeAttribute(NAME, httpBinding.getName());
+ if (restBinding.getName() != null) {
+ writer.writeAttribute(NAME, restBinding.getName());
}
// Write binding URI
- if (httpBinding.getURI() != null) {
- writer.writeAttribute(URI, httpBinding.getURI());
+ if (restBinding.getURI() != null) {
+ writer.writeAttribute(URI, restBinding.getURI());
+ }
+
+ // Write operation selectors
+ if ( restBinding.getOperationSelector() != null ) {
+ extensionProcessor.write(restBinding.getOperationSelector(),
writer, context);
+ }
+
+ // Write wire formats
+ if ( restBinding.getRequestWireFormat() != null ) {
+ extensionProcessor.write(restBinding.getRequestWireFormat(),
writer, context);
}
writeEnd(writer);
Copied:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory
(from r937844,
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor)
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory?p2=tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory&p1=tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor&r1=937844&r2=937845&rev=937845&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory
Sun Apr 25 17:51:44 2010
@@ -15,5 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.binding.rest.xml.RESTBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.rest,model=org.apache.tuscany.sca.binding.rest.RESTBinding,factory=org.apache.tuscany.sca.binding.rest.RESTBindingFactory
+# Implementation class for model factory
+org.apache.tuscany.sca.binding.rest.wireformat.json.impl.RESTWireFormatJSONFactoryImpl
\ No newline at end of file
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor?rev=937845&r1=937844&r2=937845&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
Sun Apr 25 17:51:44 2010
@@ -17,3 +17,6 @@
# Implementation class for the artifact processor extension
org.apache.tuscany.sca.binding.rest.xml.RESTBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.rest,model=org.apache.tuscany.sca.binding.rest.RESTBinding,factory=org.apache.tuscany.sca.binding.rest.RESTBindingFactory
+
+# Implementation class for the wireFormat processor extension
+org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.json,model=org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSON,factory=org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSONFactory
\ No newline at end of file
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java?rev=937845&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
Sun Apr 25 17:51:44 2010
@@ -0,0 +1,125 @@
+/*
+ * 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.rest.wireformat.json.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.WireFormat;
+import org.apache.tuscany.sca.binding.rest.RESTBinding;
+import org.apache.tuscany.sca.binding.rest.wireformat.json.RESTWireFormatJSON;
+import
org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import
org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import
org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * JSON wire format processor tests to verify properly processing of
+ * wireFormat content in binding configuration in the composite file
+ *
+ * @version $Rev$ $Date$
+ */
+public class RESTWireFormatJSONProcessorTestCase {
+
+ public static final String COMPOSITE_WITH_WIRE_FORMAT =
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ + "<composite
xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"
xmlns:ns1=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"
targetNamespace=\"http://binding-rest\" name=\"binding-rest\">"
+ + "<component name=\"HelloWorldComponent\">"
+ + "<implementation.java class=\"services.HelloWorld\" />"
+ + "<service name=\"HelloWorldService\">"
+ + "<ns1:binding.rest
xmlns:ns1=\"http://tuscany.apache.org/xmlns/sca/1.1\"
uri=\"http://localhost:8080/uri\">"
+ + "<ns1:wireFormat.json />"
+ + "</ns1:binding.rest>"
+ + "</service>"
+ + "</component>"
+ + "</composite>";
+
+ public static final String BINDING_WITH_WIRE_FORMAT =
+ "<binding.rest xmlns=\"http://tuscany.apache.org/xmlns/sca/1.1\"
uri=\"http://localhost:8080/uri\">"
+ + "<wireFormat.json />"
+ + "</binding.rest>";
+
+ private static XMLInputFactory inputFactory;
+ private static XMLOutputFactory outputFactory;
+ private static ExtensibleStAXArtifactProcessor staxProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new
DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+
+ context = new ProcessorContext(extensionPoints);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = new
DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors,
inputFactory, outputFactory);
+
+ }
+
+ /**
+ * Tests the APIs:
+ * public WireFormat getRequstWireFormat();
+ * public WireFormat getResponseWireFormat();
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testWireFormat() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new
StringReader(BINDING_WITH_WIRE_FORMAT));
+
+ RESTBinding binding = (RESTBinding)staxProcessor.read(reader,
context);
+ Assert.assertNotNull(binding);
+
+ WireFormat requestWireFormat = binding.getRequestWireFormat();
+ Assert.assertEquals(RESTWireFormatJSON.class,
requestWireFormat.getClass().getInterfaces()[0]);
+
+ WireFormat responseWireFormat = binding.getResponseWireFormat();
+ Assert.assertEquals(RESTWireFormatJSON.class,
responseWireFormat.getClass().getInterfaces()[0]);
+ }
+
+ @Test
+ public void testWriteWireFormat() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new
StringReader(BINDING_WITH_WIRE_FORMAT));
+
+ RESTBinding binding = (RESTBinding)staxProcessor.read(reader, context);
+ Assert.assertNotNull(binding);
+ reader.close();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(binding, bos, context);
+
+ // used for debug comparison
+ System.out.println(BINDING_WITH_WIRE_FORMAT);
+ System.out.println(bos.toString());
+
+ Assert.assertEquals(BINDING_WITH_WIRE_FORMAT, bos.toString());
+
+ }
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/impl/RESTWireFormatJSONProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date