summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store')
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java54
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java29
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java38
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java76
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Item.java50
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Items.java37
6 files changed, 284 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java
new file mode 100644
index 0000000000..5fb29782f2
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java
@@ -0,0 +1,54 @@
+/*
+ * 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.store;
+
+import java.util.Date;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+
+@Remotable
+public interface Catalog {
+
+ @GET
+ Items getItem();
+
+ @GET
+ @Path("{id}")
+ Item getItemById(@PathParam("id") String itemId, @HeaderParam("If-Modified-Since") Date date);
+
+ @POST
+ void addItem(Item item);
+
+ @PUT
+ void updateItem(Item item);
+
+ @DELETE
+ @Path("{id}")
+ void deleteItem(@PathParam("id") String itemId);
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java
new file mode 100644
index 0000000000..45f8949633
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/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.store;
+
+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/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java
new file mode 100644
index 0000000000..9956e207e1
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/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.store;
+
+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/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java
new file mode 100644
index 0000000000..447e983aa7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java
@@ -0,0 +1,76 @@
+/*
+ * 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.store;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Property;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class FruitsCatalogImpl implements Catalog {
+
+ @Property
+ public String currencyCode = "USD";
+
+ @Reference
+ public CurrencyConverter currencyConverter;
+
+ private Map<String, Item> catalog = new HashMap<String, Item>();
+
+ @Init
+ public void init() {
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ catalog.put("Apple", new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99)));
+ catalog.put("Orange", new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55)));
+ catalog.put("Pear", new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55)));
+ }
+
+ public Items getItem() {
+ Items items = new Items();
+ items.setItems(new ArrayList<Item>(catalog.values()));
+ return items;
+ }
+
+ public Item getItemById(String itemId, Date date) {
+ return catalog.get(itemId);
+ }
+
+ public void addItem(Item item) {
+ catalog.put(item.getName(),item);
+ }
+
+ public void updateItem(Item item) {
+ if(catalog.get(item.getName()) != null) {
+ catalog.put(item.getName(), item);
+ }
+ }
+
+ public void deleteItem(String itemId) {
+ if(catalog.get(itemId) != null) {
+ catalog.remove(itemId);
+ }
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Item.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Item.java
new file mode 100644
index 0000000000..d5a298eee5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/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.store;
+
+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/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Items.java b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Items.java
new file mode 100644
index 0000000000..82a995943d
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-rest-runtime/src/test/java/services/store/Items.java
@@ -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 services.store;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class Items {
+ private List<Item> items;
+
+ public List<Item> getItems() {
+ return items;
+ }
+
+ public void setItems(List<Item> items) {
+ this.items = items;
+ }
+}