summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/test')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java4
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java80
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/JSONWireFormatTestCase.java24
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java27
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java29
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java38
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java52
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java50
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite40
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/test.composite7
10 files changed, 342 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java
index e68646c8a5..4db7fd64dc 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java
@@ -107,8 +107,8 @@ public class RESTBindingCacheTestCase {
int index = 0;
String content = "";
String request = MessageFormat.format(REQUEST2, "GET", index,
- "If-Modified-Since", dateFormat.format(new Date(0)), content
- .getBytes().length, content);
+ "If-Modified-Since", dateFormat.format(new Date(0)),
+ content.getBytes().length, content);
os.write(request.getBytes());
os.flush();
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
new file mode 100644
index 0000000000..9967fe4d71
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * 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 java.net.Socket;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import services.Catalog;
+import services.Item;
+
+@Ignore
+public class CatalogServiceTestCase {
+ private static Node node;
+ private static Catalog catalogService;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(CatalogServiceTestCase.class);
+ node = NodeFactory.newInstance().createNode("store.composite", new Contribution("catalog", contribution));
+ node.start();
+
+ catalogService = node.getService(Catalog.class, "Catalog");
+ Assert.assertNotNull(catalogService);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if(node != null) {
+ node.stop();
+ }
+ }
+
+ @Test
+ public void testPing() throws Exception {
+ new Socket("127.0.0.1", 8085);
+ System.in.read();
+ }
+
+ @Test
+ public void testNewsService() throws Exception {
+ Item[] items = catalogService.get();
+
+ Assert.assertNotNull(items);
+ Assert.assertTrue(items.length > 0);
+
+ for(int pos = 0; pos < items.length; pos++) {
+ System.out.println(">>> Item[" + pos + "] - " + items[pos].getName() + " - " + items[pos].getPrice());
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/JSONWireFormatTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/JSONWireFormatTestCase.java
new file mode 100644
index 0000000000..5159cf6893
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/JSONWireFormatTestCase.java
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public class JSONWireFormatTestCase {
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
new file mode 100644
index 0000000000..b5e504fe11
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface Catalog {
+ Item[] get();
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java
new file mode 100644
index 0000000000..a064f3dd69
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface CurrencyConverter {
+ public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount);
+
+ public String getCurrencySymbol(String currencyCode);
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java
new file mode 100644
index 0000000000..c354aed447
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+public class CurrencyConverterImpl implements CurrencyConverter {
+ public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) {
+ if (toCurrencyCode.equals("USD"))
+ return amount;
+ else if (toCurrencyCode.equals("EUR"))
+ return ((double)Math.round(amount * 0.7256 * 100)) /100;
+ return 0;
+ }
+
+ public String getCurrencySymbol(String currencyCode) {
+ if (currencyCode.equals("USD"))
+ return "$";
+ else if (currencyCode.equals("EUR"))
+ return "E"; //"€";
+ return "?";
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java
new file mode 100644
index 0000000000..d132a24b00
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java
@@ -0,0 +1,52 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Property;
+import org.oasisopen.sca.annotation.Reference;
+
+public class FruitsCatalogImpl implements Catalog {
+
+ @Property
+ public String currencyCode = "USD";
+
+ @Reference
+ public CurrencyConverter currencyConverter;
+
+ private List<Item> catalog = new ArrayList<Item>();
+
+ @Init
+ public void init() {
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99)));
+ catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55)));
+ catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55)));
+ }
+
+ public Item[] get() {
+ Item[] catalogArray = new Item[catalog.size()];
+ catalog.toArray(catalogArray);
+ return catalogArray;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java
new file mode 100644
index 0000000000..fe32cfc828
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+public class Item {
+ private String name;
+ private String price;
+
+ public Item() {
+ }
+
+ public Item(String name, String price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPrice() {
+ return price;
+ }
+
+ public void setPrice(String price) {
+ this.price = price;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
new file mode 100644
index 0000000000..72219337b6
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
@@ -0,0 +1,40 @@
+<?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"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://store"
+ name="store">
+
+ <component name="Catalog">
+ <implementation.java class="services.FruitsCatalogImpl"/>
+ <property name="currencyCode">USD</property>
+ <service name="Catalog">
+ <tuscany:binding.rest uri="http://localhost:8085/Catalog">
+ <tuscany:wireFormat.json />
+ </tuscany:binding.rest>
+ </service>
+ <reference name="currencyConverter" target="CurrencyConverter"/>
+ </component>
+
+ <component name="CurrencyConverter">
+ <implementation.java class="services.CurrencyConverterImpl"/>
+ </component>
+
+</composite>
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/test.composite b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/test.composite
index 9fbce7c427..835633ac6d 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/test.composite
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/test.composite
@@ -23,13 +23,6 @@
xmlns:sr="http://sample/test"
name="test">
- <!-- component name="ResourceServiceComponent">
- <tuscany:implementation.resource location="content"/>
- <service name="Resource">
- <tuscany:binding.rest uri="http://localhost:8085/webcontent"/>
- </service>
- </component -->
-
<component name="HTTPServiceComponent">
<implementation.java class="org.apache.tuscany.sca.binding.rest.TestServiceImpl"/>
<service name="Servlet">