You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2006/10/30 10:46:41 UTC
svn commit: r469105 - in
/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc: ./
src/main/java/org/apache/tuscany/binding/jsonrpc/
src/main/java/org/apache/tuscany/binding/jsonrpc/util/ src/test/
src/test/java/ src/test/java/org/ src/test/jav...
Author: antelder
Date: Mon Oct 30 01:46:40 2006
New Revision: 469105
URL: http://svn.apache.org/viewvc?view=rev&rev=469105
Log:
TUSCANY-884, apply patch from Bert Lamb: add Dojo support to jsonrpc binding
Added:
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmd.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilderTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoaderTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServletTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCServiceTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServletTestCase.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/TestInterface.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmdTestCase.java
Modified:
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/pom.xml
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java
incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/pom.xml?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/pom.xml (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/pom.xml Mon Oct 30 01:46:40 2006
@@ -54,6 +54,30 @@
<version>5.0.18</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>core</artifactId>
+ <version>${sca.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.json-lib</groupId>
+ <artifactId>json-lib</artifactId>
+ <version>0.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>httpunit</groupId>
+ <artifactId>httpunit</artifactId>
+ <version>1.6.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java Mon Oct 30 01:46:40 2006
@@ -26,7 +26,7 @@
* @version $Rev$ $Date$
*/
public class JSONRPCBinding extends Binding {
- private String uri;
+ String uri;
public String getURI() {
return uri;
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java Mon Oct 30 01:46:40 2006
@@ -33,7 +33,7 @@
*/
public class JSONRPCBindingBuilder extends BindingBuilderExtension<JSONRPCBinding> {
- private ServletHost servletHost;
+ ServletHost servletHost;
@Autowire()
public void setServletHost(ServletHost servletHost) {
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java Mon Oct 30 01:46:40 2006
@@ -41,8 +41,7 @@
public class JSONRPCBindingLoader extends LoaderExtension<JSONRPCBinding> {
public static final QName BINDING_JSON = new QName(XML_NAMESPACE_1_0, "binding.jsonrpc");
- public JSONRPCBindingLoader(@Autowire
- LoaderRegistry registry) {
+ public JSONRPCBindingLoader(@Autowire LoaderRegistry registry) {
super(registry);
}
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java Mon Oct 30 01:46:40 2006
@@ -18,13 +18,22 @@
*/
package org.apache.tuscany.binding.jsonrpc;
+import java.io.BufferedReader;
+import java.io.CharArrayWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.text.ParseException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.apache.tuscany.binding.jsonrpc.util.JavaToSmd;
+import org.json.JSONObject;
+
import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import com.metaparadigm.jsonrpc.JSONRPCResult;
import com.metaparadigm.jsonrpc.JSONRPCServlet;
/**
@@ -34,38 +43,99 @@
public class JSONRPCEntryPointServlet extends JSONRPCServlet {
private static final long serialVersionUID = 1L;
+ private static final int BUF_SIZE = 4096;
+
String serviceName;
Object serviceInstance;
- public JSONRPCEntryPointServlet(String serviceName, Object serviceInstance) {
- this.serviceName = serviceName;
- this.serviceInstance = serviceInstance;
+ Class<?> serviceInterface;
+ // default constructor for unit testing
+ public JSONRPCEntryPointServlet() {
}
- /*
- * (non-Javadoc)
- *
- * @see com.metaparadigm.jsonrpc.JSONRPCServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
- */
+ public JSONRPCEntryPointServlet(String serviceName, Class<?> serviceInterface, Object serviceInstance) {
+ this.serviceName = serviceName;
+ this.serviceInterface = serviceInterface;
+ this.serviceInstance = serviceInstance;
+ }
+
@Override
- public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ClassCastException {
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ClassCastException {
- /*
- * Create a new bridge for every request to aviod all the problems with JSON-RPC-Java storing the bridge in the session
- */
- HttpSession session = request.getSession();
- try {
+ // if there is a smd parameter, we should retrun the SMD for this service
+ if (request.getParameter("smd") != null) {
+ String serviceUrl = request.getRequestURL().toString();
+ String smd = JavaToSmd.interfaceToSmd(serviceInterface, serviceUrl);
+
+ response.setContentType("text/plain;charset=utf-8");
+ OutputStream out = response.getOutputStream();
+ byte[] bout = smd.getBytes("UTF-8");
+
+ out.write(bout);
+ out.flush();
+ out.close();
+ } else {
+ /*
+ * Create a new bridge for every request to aviod all the problems with
+ * JSON-RPC-Java storing the bridge in the session
+ */
+ HttpSession session = request.getSession();
JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
- jsonrpcBridge.registerObject(serviceName, serviceInstance);
+ jsonrpcBridge.registerObject(serviceName, serviceInstance, serviceInterface);
session.setAttribute("JSONRPCBridge", jsonrpcBridge);
- super.service(request, response);
+ // Encode using UTF-8, although We are actually ASCII clean as
+ // all unicode data is JSON escaped using backslash u. This is
+ // less data efficient for foreign character sets but it is
+ // needed to support naughty browsers such as Konqueror and Safari
+ // which do not honour the charset set in the response
+ response.setContentType("text/plain;charset=utf-8");
+ OutputStream out = response.getOutputStream();
+
+ // Decode using the charset in the request if it exists otherwise
+ // use UTF-8 as this is what all browser implementations use.
+ // The JSON-RPC-Java JavaScript client is ASCII clean so it
+ // although here we can correctly handle data from other clients
+ // that do not escape non ASCII data
+ String charset = request.getCharacterEncoding();
+ if (charset == null) {
+ charset = "UTF-8";
+ }
+ BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset));
+
+ // Read the request
+ CharArrayWriter data = new CharArrayWriter();
+ char buf[] = new char[BUF_SIZE];
+ int ret;
+ while ((ret = in.read(buf, 0, BUF_SIZE)) != -1) {
+ data.write(buf, 0, ret);
+ }
+
+ // Process the request
+ JSONObject jsonReq = null;
+ JSONRPCResult jsonResp = null;
+ try {
+ jsonReq = new JSONObject(data.toString());
+ String method = jsonReq.getString("method");
+ if ((method != null) && (method.indexOf('.') < 0)) {
+ jsonReq.putOpt("method", serviceName + "." + method);
+ }
+ jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);
+ } catch (ParseException e) {
+ throw new RuntimeException("Unable to parse request", e);
+ }
+
+ byte[] bout = jsonResp.toString().getBytes("UTF-8");
+
+ out.write(bout);
+ out.flush();
+ out.close();
- } finally {
- session.removeAttribute("JSONRPCBridge");
}
}
+
}
Modified: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java?view=diff&rev=469105&r1=469104&r2=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java (original)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java Mon Oct 30 01:46:40 2006
@@ -28,9 +28,13 @@
* @version $Rev$ $Date$
*/
public class JSONRPCService extends ServiceExtension {
- private ServletHost servletHost;
+
private static int servletRegistrationCount = 0;
+ private ServletHost servletHost;
+
+ public static final String SCRIPT_GETTER_SERVICE_MAPPING = "/SCA/scripts";
+
public JSONRPCService(String theName, Class<?> interfaze, CompositeComponent parent, WireService wireService, ServletHost servletHost) {
super(theName, interfaze, parent, wireService);
@@ -41,21 +45,31 @@
public synchronized void start() {
super.start();
- JSONRPCEntryPointServlet servlet = new JSONRPCEntryPointServlet(getName(), this.getServiceInstance());
+ JSONRPCEntryPointServlet servlet = new JSONRPCEntryPointServlet(getName(), interfaze, this.getServiceInstance());
+
+ // register the servlet based on the service name
servletHost.registerMapping("/" + getName(), servlet);
- if((servletRegistrationCount == 0) && (!servletHost.isMappingRegistered("/SCA/scripts"))) {
- servletHost.registerMapping("/SCA/scripts", new ScriptGetterServlet());
+
+ // if the script getter servlet is not already registered then register it
+ if ((servletRegistrationCount == 0) && (!servletHost.isMappingRegistered("/SCA/scripts"))) {
+ servletHost.registerMapping(SCRIPT_GETTER_SERVICE_MAPPING, new ScriptGetterServlet());
}
+
+ // increase the registered servlet count
servletRegistrationCount++;
}
@Destroy
public synchronized void stop() {
+ // unregister the service servlet
servletHost.unregisterMapping("/" + getName());
+
+ // decrement the registered servlet count
servletRegistrationCount--;
- if(servletRegistrationCount == 0)
- {
- servletHost.unregisterMapping("/SCA/scripts");
+
+ // if this was the last servlet, we can now unregister the script getter servlet
+ if (servletRegistrationCount == 0) {
+ servletHost.unregisterMapping(SCRIPT_GETTER_SERVICE_MAPPING);
}
super.stop();
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmd.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmd.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmd.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmd.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,49 @@
+/*
+ * 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.binding.jsonrpc.util;
+
+import java.lang.reflect.Method;
+
+
+public class JavaToSmd {
+
+ public static String interfaceToSmd(Class klazz, String serviceUrl) {
+ String name = klazz.getSimpleName();
+ Method methods[] = klazz.getMethods();
+
+ StringBuffer smdSb = new StringBuffer();
+ smdSb.append("{\"SMDVersion\":\".1\",\"objectName\":\"" + name + "\",\"serviceType\":\"JSON-RPC\",\"serviceURL\":\""+ serviceUrl + "\",\"methods\":[");
+ for (int i = 0; i < methods.length; i++) {
+ if (i != 0) smdSb.append(",");
+ Class<?> params[] = methods[i].getParameterTypes();
+ smdSb.append("{\"name\":\""+methods[i].getName() + "\",\"parameters\":[");
+ for (int j = 0; j < params.length; j++) {
+ if (j != 0) smdSb.append(",");
+ // right now Dojo doesn't look at the type value, so we'll default it to STRING
+ // also, since we can't introspect the method paramater names we'll just create an incrementing parameter name
+ smdSb.append("{\"name\":\"param" + j + "\",\"type\":\"STRING\"}");
+ }
+ smdSb.append("]}");
+ }
+ smdSb.append("]}");
+
+ return smdSb.toString();
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilderTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilderTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilderTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,74 @@
+/*
+ * 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.binding.jsonrpc;
+
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.*;
+
+public class JSONRPCBindingBuilderTestCase extends TestCase {
+
+ public void testSetServletHost() {
+ JSONRPCBindingBuilder bindingBuilder = new JSONRPCBindingBuilder();
+ ServletHost mockServletHost = createMock(ServletHost.class);
+ replay(mockServletHost);
+ bindingBuilder.setServletHost(mockServletHost);
+ assertEquals(mockServletHost, bindingBuilder.servletHost);
+ }
+
+ public void testGetBindingType() {
+ JSONRPCBindingBuilder bindingBuilder = new JSONRPCBindingBuilder();
+ assertEquals(JSONRPCBinding.class, bindingBuilder.getBindingType());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testBuildCompositeComponentBoundServiceDefinitionOfJSONRPCBindingDeploymentContext() {
+ JSONRPCBindingBuilder bindingBuilder = new JSONRPCBindingBuilder();
+ CompositeComponent mockParent = createMock(CompositeComponent.class);
+ replay(mockParent);
+ BoundServiceDefinition<JSONRPCBinding> mockServiceDefinition = createMock((new BoundServiceDefinition<JSONRPCBinding>()).getClass());
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ try {
+ ServiceContract<?> contract = registry.introspect(JSONRPCService.class);
+
+ expect(mockServiceDefinition.getServiceContract()).andStubReturn(contract);
+ expect(mockServiceDefinition.getName()).andReturn("test_service");
+ replay(mockServiceDefinition);
+ DeploymentContext mockDeploymentContext = createMock(DeploymentContext.class);
+ replay(mockDeploymentContext);
+
+ JSONRPCService jsonService = (JSONRPCService)bindingBuilder.build(mockParent, mockServiceDefinition, mockDeploymentContext);
+ assertEquals(JSONRPCService.class, jsonService.getInterface());
+
+ } catch (InvalidServiceContractException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ }
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoaderTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoaderTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoaderTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.binding.jsonrpc;
+
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+public class JSONRPCBindingLoaderTestCase extends TestCase {
+
+ public void testJSONRPCBindingLoader() {
+ LoaderRegistry mockRegistry = createMock(LoaderRegistry.class);
+ replay(mockRegistry);
+ JSONRPCBindingLoader loader = new JSONRPCBindingLoader(mockRegistry);
+ assertNotNull(loader);
+ }
+
+ public void testGetXMLType() {
+ LoaderRegistry mockRegistry = createMock(LoaderRegistry.class);
+ replay(mockRegistry);
+ JSONRPCBindingLoader loader = new JSONRPCBindingLoader(mockRegistry);
+ assertNotNull(loader);
+ assertEquals(JSONRPCBindingLoader.BINDING_JSON, loader.getXMLType());
+ }
+
+ public void testLoad() {
+ LoaderRegistry mockRegistry = createMock(LoaderRegistry.class);
+ replay(mockRegistry);
+ JSONRPCBindingLoader loader = new JSONRPCBindingLoader(mockRegistry);
+ assertNotNull(loader);
+
+ CompositeComponent mockParent = createMock(CompositeComponent.class);
+ replay(mockParent);
+ ModelObject mockModelObject = createMock(ModelObject.class);
+ replay(mockModelObject);
+ XMLStreamReader mockReader = createMock(XMLStreamReader.class);
+ replay(mockReader);
+ DeploymentContext mockDeploymentContext = createMock(DeploymentContext.class);
+ replay(mockDeploymentContext);
+
+ try {
+ JSONRPCBinding jsonBinding = loader.load(mockParent, mockModelObject, mockReader, mockDeploymentContext);
+ assertNotNull(jsonBinding);
+ } catch (LoaderException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ } catch (XMLStreamException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ }
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,37 @@
+/*
+ * 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.binding.jsonrpc;
+
+import junit.framework.TestCase;
+
+public class JSONRPCBindingTestCase extends TestCase {
+
+ public void testGetURI() {
+ JSONRPCBinding jsonBinding = new JSONRPCBinding();
+ jsonBinding.uri = "test_uri";
+ assertEquals("test_uri", jsonBinding.getURI());
+ }
+
+ public void testSetURI() {
+ JSONRPCBinding jsonBinding = new JSONRPCBinding();
+ jsonBinding.setURI("test_uri");
+ assertEquals("test_uri", jsonBinding.uri);
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServletTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServletTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServletTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServletTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,186 @@
+/*
+ * 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.binding.jsonrpc;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.HashMap;
+
+import javax.servlet.ServletException;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.PostMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.InvocationContext;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+
+public class JSONRPCEntryPointServletTestCase extends TestCase implements TestInterface{
+
+ private static final String MESSAGE = "Testing..1..2..3";
+ private static final String SERVICE_PATH = "JsonRpc/Test";
+ private static final String SERVICE_URL = "http://localhost/" + SERVICE_PATH;
+ ServletRunner sr = null;
+
+
+ protected void setUp() throws Exception
+ {
+ sr = new ServletRunner();
+ sr.registerServlet( SERVICE_PATH, JSONRPCEntryPointServlet.class.getName() );
+ }
+
+ public void testJSONRPCEntryPointServletContruct() {
+ JSONRPCEntryPointServlet servlet = new JSONRPCEntryPointServlet("serviceName",TestInterface.class, this);
+ assertEquals("serviceName", servlet.serviceName);
+ assertEquals(TestInterface.class, servlet.serviceInterface);
+ assertEquals(this, servlet.serviceInstance);
+ }
+
+ public void testGetSmd() throws IOException {
+ ServletUnitClient sc = sr.newClient();
+ WebRequest request = new GetMethodWebRequest( SERVICE_URL );
+ request.setParameter( "smd", "" );
+ InvocationContext ic = sc.newInvocation( request );
+ try {
+ JSONRPCEntryPointServlet jsonServlet = (JSONRPCEntryPointServlet)ic.getServlet();
+ jsonServlet.serviceName = "Test";
+ jsonServlet.serviceInterface = TestInterface.class;
+ jsonServlet.serviceInstance = this;
+
+ ic.service();
+ WebResponse response = ic.getServletResponse();
+ assertEquals(200, response.getResponseCode());
+ JSONObject jsonResp = new JSONObject(response.getText());
+ assertEquals("TestInterface", jsonResp.getString("objectName"));
+ assertEquals("JSON-RPC", jsonResp.getString("serviceType"));
+ assertEquals(SERVICE_URL, jsonResp.getString("serviceURL"));
+ JSONArray jsonMethods = jsonResp.getJSONArray("methods");
+ assertNotNull(jsonMethods);
+ assertEquals(2, jsonMethods.length());
+ HashMap<String, JSONObject> hashMethods = new HashMap<String, JSONObject>();
+ for(int i = 0; i < jsonMethods.length(); i++)
+ {
+ JSONObject method = jsonMethods.getJSONObject(i);
+ assertNotNull(method);
+ assertNotNull(method.getString("name"));
+ hashMethods.put(method.getString("name"), method);
+ }
+ JSONObject echoMethod = hashMethods.get("echo");
+ assertNotNull(echoMethod);
+ JSONArray echoParameters = echoMethod.getJSONArray("parameters");
+ assertNotNull(echoParameters);
+ assertEquals(1,echoParameters.length());
+ assertEquals("param0",echoParameters.getJSONObject(0).getString("name"));
+ assertEquals("STRING",echoParameters.getJSONObject(0).getString("type"));
+ JSONObject getMessageMethod = hashMethods.get("getMessage");
+ assertNotNull(getMessageMethod);
+ JSONArray getMessageParameters = getMessageMethod.getJSONArray("parameters");
+ assertNotNull(getMessageParameters);
+ assertEquals(0,getMessageParameters.length());
+
+ } catch (ServletException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ }
+
+
+ }
+
+ public void testZeroParameterMethodCall() throws IOException {
+ ServletUnitClient sc = sr.newClient();
+
+ try {
+ JSONObject jsonRequest = new JSONObject("{ \"method\": \"getMessage\", \"params\": [], \"id\": 1}");
+
+ WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
+ InvocationContext ic = sc.newInvocation( request );
+
+ JSONRPCEntryPointServlet jsonServlet = (JSONRPCEntryPointServlet)ic.getServlet();
+ jsonServlet.serviceName = "Test";
+ jsonServlet.serviceInterface = TestInterface.class;
+ jsonServlet.serviceInstance = this;
+
+ ic.service();
+ WebResponse response = ic.getServletResponse();
+ assertEquals(200, response.getResponseCode());
+ JSONObject jsonResp = new JSONObject(response.getText());
+ assertEquals(MESSAGE, jsonResp.getString("result"));
+ } catch (ServletException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ }
+
+
+ }
+
+ public void testMalformedJSON() throws IOException {
+ ServletUnitClient sc = sr.newClient();
+
+ try {
+ String badJsonRequest = "{\"no close brace\"";
+
+ WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(badJsonRequest.getBytes("UTF-8")),"application/json");
+ InvocationContext ic = sc.newInvocation( request );
+
+ JSONRPCEntryPointServlet jsonServlet = (JSONRPCEntryPointServlet)ic.getServlet();
+ jsonServlet.serviceName = "Test";
+ jsonServlet.serviceInterface = TestInterface.class;
+ jsonServlet.serviceInstance = this;
+
+ ic.service();
+ fail("Expected runtime exception from malformed JSON resquest");
+
+ } catch (ServletException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail(e.toString());
+ } catch (RuntimeException e) {
+ // expected runtime exception from malformed JSON request
+ assertEquals(true, e.getCause() instanceof ParseException);
+ }
+
+
+ }
+
+ public String echo(String message) {
+ return message;
+ }
+
+ public String getMessage() {
+ return MESSAGE;
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCServiceTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCServiceTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/JSONRPCServiceTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.binding.jsonrpc;
+
+import javax.servlet.Servlet;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.wire.WireService;
+
+import static org.easymock.classextension.EasyMock.*;
+
+import junit.framework.TestCase;
+
+public class JSONRPCServiceTestCase extends TestCase {
+ private static final String SERVICE_NAME = "test_service_name";
+
+ public void testStart() {
+ CompositeComponent mockParent = createMock(CompositeComponent.class);
+ replay(mockParent);
+ WireService mockWireService = createMock(WireService.class);
+ expect(mockWireService.createProxy(null)).andReturn(this);
+ replay(mockWireService);
+ ServletHost mockServletHost = createMock(ServletHost.class);
+ expect(mockServletHost.isMappingRegistered(JSONRPCService.SCRIPT_GETTER_SERVICE_MAPPING)).andReturn(false);
+ mockServletHost.registerMapping(eq("/" + SERVICE_NAME), (Servlet) notNull());
+ mockServletHost.registerMapping(eq(JSONRPCService.SCRIPT_GETTER_SERVICE_MAPPING), (Servlet) notNull());
+ replay(mockServletHost);
+
+ JSONRPCService jsonRpcService = new JSONRPCService(SERVICE_NAME, this.getClass(), mockParent, mockWireService, mockServletHost );
+ jsonRpcService.start();
+ }
+
+ public void testStop() {
+ CompositeComponent mockParent = createMock(CompositeComponent.class);
+ replay(mockParent);
+ WireService mockWireService = createMock(WireService.class);
+ expect(mockWireService.createProxy(null)).andReturn(this);
+ replay(mockWireService);
+ ServletHost mockServletHost = createMock(ServletHost.class);
+ expect(mockServletHost.isMappingRegistered(JSONRPCService.SCRIPT_GETTER_SERVICE_MAPPING)).andReturn(false);
+ mockServletHost.registerMapping(eq("/" + SERVICE_NAME), (Servlet) notNull());
+ mockServletHost.registerMapping(eq(JSONRPCService.SCRIPT_GETTER_SERVICE_MAPPING), (Servlet) notNull());
+ expect(mockServletHost.unregisterMapping(eq("/" + SERVICE_NAME))).andReturn(null);
+ expect(mockServletHost.unregisterMapping(eq(JSONRPCService.SCRIPT_GETTER_SERVICE_MAPPING))).andReturn(null);
+ replay(mockServletHost);
+
+ JSONRPCService jsonRpcService = new JSONRPCService(SERVICE_NAME, this.getClass(), mockParent, mockWireService, mockServletHost );
+ jsonRpcService.start();
+ jsonRpcService.stop();
+ }
+
+ public void testJSONRPCService() {
+ CompositeComponent mockParent = createMock(CompositeComponent.class);
+ replay(mockParent);
+ WireService mockWireService = createMock(WireService.class);
+ replay(mockWireService);
+ ServletHost mockServletHost = createMock(ServletHost.class);
+ replay(mockServletHost);
+
+ JSONRPCService jsonRpcService = new JSONRPCService(SERVICE_NAME, this.getClass(), mockParent, mockWireService, mockServletHost );
+ assertNotNull(jsonRpcService);
+ }
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServletTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServletTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServletTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServletTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.binding.jsonrpc;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.xml.sax.SAXException;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+
+public class ScriptGetterServletTestCase extends TestCase {
+
+ private static final String SERVICE_PATH = "JsonRpc/ScriptGetterTest";
+ private static final String SERVICE_URL = "http://localhost/" + SERVICE_PATH;
+ ServletRunner sr = null;
+
+
+ protected void setUp() throws Exception {
+ sr = new ServletRunner();
+ sr.registerServlet( SERVICE_PATH, ScriptGetterServlet.class.getName() );
+ }
+
+ public void testGetScript() throws IOException {
+ ServletUnitClient sc = sr.newClient();
+ WebRequest request = new GetMethodWebRequest( SERVICE_URL );
+ try {
+ WebResponse response = sc.getResponse(request);
+ assertEquals(200, response.getResponseCode());
+ } catch (SAXException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ fail(e1.toString());
+ }
+ }
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/TestInterface.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/TestInterface.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/TestInterface.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/TestInterface.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,25 @@
+/*
+ * 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.binding.jsonrpc;
+
+public interface TestInterface {
+ String getMessage();
+ String echo(String message);
+
+}
Added: incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmdTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmdTestCase.java?view=auto&rev=469105
==============================================================================
--- incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmdTestCase.java (added)
+++ incubator/tuscany/java/sca/services/bindings/binding.jsonrpc/src/test/java/org/apache/tuscany/binding/jsonrpc/util/JavaToSmdTestCase.java Mon Oct 30 01:46:40 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.binding.jsonrpc.util;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import junit.framework.TestCase;
+
+public class JavaToSmdTestCase extends TestCase {
+
+ public void testInstantiate() {
+ // this test is only really here to get 100% test coverage
+ JavaToSmd test = new JavaToSmd();
+ assertNotNull(test);
+ }
+
+ public void testInterfaceToSmd() {
+ String serviceUrl = "/testServiceUrl";
+ String smd = JavaToSmd.interfaceToSmd(java.util.Observer.class,serviceUrl);
+ assertNotNull(smd);
+ JSONObject json = new JSONObject(smd);
+ assertNotNull(json);
+ assertEquals(".1", json.getString("SMDVersion"));
+ assertEquals("Observer", json.getString("objectName"));
+ assertEquals("JSON-RPC", json.getString("serviceType"));
+ assertEquals(serviceUrl, json.getString("serviceURL"));
+ JSONArray methodsArray = json.getJSONArray("methods");
+ assertNotNull(methodsArray);
+ assertEquals(1, methodsArray.length());
+ JSONObject methodJson = methodsArray.getJSONObject(0);
+ assertNotNull(methodJson);
+ assertEquals("update", methodJson.getString("name"));
+ JSONArray parametersArray = methodJson.getJSONArray("parameters");
+ assertNotNull(parametersArray);
+ assertEquals(2, parametersArray.length());
+ JSONObject param0Json = parametersArray.getJSONObject(0);
+ assertNotNull(param0Json);
+ assertEquals("param0", param0Json.getString("name"));
+ assertEquals("STRING", param0Json.getString("type"));
+ JSONObject param1Json = parametersArray.getJSONObject(1);
+ assertNotNull(param1Json);
+ assertEquals("param1", param1Json.getString("name"));
+ assertEquals("STRING", param1Json.getString("type"));
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org