diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 07:46:08 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 07:46:08 +0000 |
commit | 6865c59e74f19ed6057d03583944b47abd6e036e (patch) | |
tree | 3324c11c7ca4f5ca12f15619ce30e9824e198480 /sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services | |
parent | 0d6d7922ed17cca55ec36ff2626d1080e76d6d13 (diff) |
Create branch for next release
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027394 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services')
13 files changed, 643 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java new file mode 100644 index 0000000000..4749383a0c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services.binary; + +import java.io.IOException; +import java.io.InputStream; + +import javax.activation.DataSource; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * + */ +@Remotable +public interface BinaryService { + @GET + InputStream get(); + + @PUT + void update(InputStream is) throws IOException; + + @POST + void create(DataSource dataSource) throws IOException; +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java new file mode 100644 index 0000000000..aefbf64504 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java @@ -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 services.binary; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.activation.DataSource; + +import org.oasisopen.sca.annotation.Scope; + +/** + * + */ +@Scope("COMPOSITE") +public class BinaryServiceImpl implements BinaryService { + private byte[] content; + private int length; + + public void create(DataSource dataSource) throws IOException { + content = new byte[10240]; + InputStream is = dataSource.getInputStream(); + length = is.read(content); + System.out.println("Content received: " + length); + } + + public InputStream get() { + byte[] bytes = new byte[length]; + System.arraycopy(content, 0, bytes, 0, length); + System.out.println("Content sent: " + length); + return new ByteArrayInputStream(bytes); + } + + public void update(InputStream is) throws IOException { + length = is.read(content); + System.out.println("Content updated: " + length); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java new file mode 100644 index 0000000000..08506ebd48 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java @@ -0,0 +1,70 @@ +/* + * 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.customer; + + +/** + * Customer data + */ +public class Customer { + private String id; + private String email; + private String name; + + public Customer() { + super(); + } + + public Customer(String id, String name, String email) { + super(); + this.id = id; + this.email = email; + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + return "id: " + id + " name: " + name + " e-mail: " + email; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java new file mode 100644 index 0000000000..94ebc1e1b8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java @@ -0,0 +1,46 @@ +/* + * 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.customer; + +import javax.jws.WebResult; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.core.Response; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface CustomerService { + + @GET + @WebResult(name = "Customer", targetNamespace = "") + Customer get(); + + @GET + @WebResult(name = "Customer", targetNamespace = "") + Response getResponse(); + + @POST + Response addCustomer(Customer customer); + + @PUT + void updateCustomer(Customer customer); +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java new file mode 100644 index 0000000000..22e63e0f91 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java @@ -0,0 +1,58 @@ +/* + * 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.customer; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.Response; + +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; + +@Scope("COMPOSITE") +public class CustomerServiceImpl implements CustomerService { + private Map<String, Customer> customers = new HashMap<String, Customer>(); + + @Init + public void init() { + customers.put("John", new Customer("John", "John", "john@domain.com")); + } + + public Customer get() { + return customers.values().iterator().next(); + } + + public Response getResponse() { + return Response.ok(get()).build(); + } + + public Response addCustomer(Customer customer) { + customers.put(customer.getName(), customer); + return Response.created(URI.create("/001")).build(); + } + + public void updateCustomer(Customer customer) { + if(customers.get(customer.getName()) != null) { + customers.put(customer.getName(), customer); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/Echo.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/Echo.java new file mode 100644 index 0000000000..b93ff0838b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/Echo.java @@ -0,0 +1,41 @@ +/* + * 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.echo; + +import javax.ws.rs.QueryParam; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Interface of our sample JSONRPC service. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Echo { + + String echo(@QueryParam("msg") String msg); + + int echoInt(@QueryParam("param") int param); + + String [] echoArrayString(@QueryParam("msgArray") String[] stringArray); + + int [] echoArrayInt(@QueryParam("intArray") int[] intArray); + +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/EchoImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/EchoImpl.java new file mode 100644 index 0000000000..6bc22bd41a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/echo/EchoImpl.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package services.echo; + + +/** + * A simple client component that uses a reference with an JSONRPC binding. + * + * @version $Rev$ $Date$ + */ +public class EchoImpl implements Echo { + + public String echo(String msg) { + return msg; + } + + public int echoInt(int param) { + int value = param; + return value; + } + + public String[] echoArrayString(String[] stringArray) { + return stringArray; + } + + public int[] echoArrayInt(int[] intArray) { + return intArray; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java new file mode 100644 index 0000000000..7e579c6aba --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java @@ -0,0 +1,51 @@ +/* + * 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 javax.ws.rs.DELETE; +import javax.ws.rs.GET; +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); + + @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-Beta1/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java b/sca-java-2.x/branches/2.0-Beta1/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-Beta1/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-Beta1/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java b/sca-java-2.x/branches/2.0-Beta1/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-Beta1/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-Beta1/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java new file mode 100644 index 0000000000..afe3d3863e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta1/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.HashMap; +import java.util.List; +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) { + 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-Beta1/modules/binding-rest-runtime/src/test/java/services/store/Item.java b/sca-java-2.x/branches/2.0-Beta1/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-Beta1/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-Beta1/modules/binding-rest-runtime/src/test/java/services/store/Items.java b/sca-java-2.x/branches/2.0-Beta1/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-Beta1/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; + } +} |