summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-http-runtime/src/test
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-11-11 00:53:16 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-11-11 00:53:16 +0000
commitcd07713f408a9edc820fb70a7dead012ee1ff899 (patch)
treebaea598f776a47141d9afc49f453200ba1f947f2 /sca-java-2.x/trunk/modules/binding-http-runtime/src/test
parentc607b0cf671eda11eff333748e4ce3a75ce941d1 (diff)
Refactoring binding http model to bring back support for servlet based resources, and making rpc style it's own operationSelector
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1200669 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-http-runtime/src/test')
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java79
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java55
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite12
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite12
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite33
11 files changed, 189 insertions, 14 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java
new file mode 100644
index 0000000000..edbb111198
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * HTTP binding unit tests for Helloworld service.
+ */
+public class ResourceServiceTestCase {
+
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ node = NodeFactory.newInstance().createNode("resource.composite", new String[] {"target/test-classes"});
+ node.start();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if (node != null) {
+ node.stop();
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ URL url = new URL("http://localhost:8080/resource");
+ InputStream is = url.openStream();
+ Assert.assertTrue(read(is).startsWith("Resource"));
+ }
+
+ private static String read(InputStream is) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java
index 2c33895f67..73bd908db8 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class BeanA {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
index cf0d457317..5c3ef631d7 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
index 9395024e5b..f41ca498c1 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class ComplexStuffImpl implements ComplexStuff {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java
index 17a0b28fdb..4ecda47d71 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
index e245f607f1..f0a24a6d9a 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class HelloworldImpl implements Helloworld {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java
new file mode 100644
index 0000000000..612a61247d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java
@@ -0,0 +1,55 @@
+/*
+ * 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 services;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.oasisopen.sca.annotation.Service;
+
+@Service(Servlet.class)
+public class ResourceService extends HttpServlet implements Servlet {
+ private static final long serialVersionUID = 8240260033930060726L;
+
+ public void init(ServletConfig config) throws ServletException {
+ }
+
+ public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.addHeader("Content-Type","text/plain");
+ response.getOutputStream().print("Resource request sucessfuly handled : " + request.getRequestURI() +'\n');
+ }
+
+ public void destroy() {
+ }
+
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ public String getServletInfo() {
+ return null;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java
index f4ffd19c9c..f65c22dc05 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class SomeException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
index 7f4cc64fe2..9aa3e26c6c 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
@@ -23,17 +23,21 @@
name="ComplexStuff">
<component name="ComplexComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="ComplexXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
index 7497cfcbac..8b8b2877cd 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
@@ -23,17 +23,21 @@
name="helloworld">
<component name="HelloworldComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="HelloworldXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite
new file mode 100644
index 0000000000..27b229e483
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ targetNamespace="http://sample/test"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ name="ResourceService">
+
+
+ <component name="ResourceComponent">
+ <implementation.java class="services.ResourceService" />
+ <service name="Servlet">
+ <tuscany:binding.http uri="/resource" />
+ </service>
+ </component>
+
+</composite> \ No newline at end of file