diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/test')
3 files changed, 28 insertions, 14 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java index cd69cd0c41..9e1b99c9bc 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java @@ -73,17 +73,11 @@ public class CustomerServiceTestCase { @Test public void testGetInvocation() throws Exception { WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL); + WebRequest request = new GetMethodWebRequest(SERVICE_URL+"/John"); request.setHeaderField("Content-Type", "application/xml"); WebResponse response = wc.getResource(request); //for debug purposes - //list the response headers - //for(String headerField : response.getHeaderFieldNames()) { - // System.out.println(">>> Header:" + headerField + " - " + response.getHeaderField(headerField)); - //} - - //for debug purposes System.out.println(">>>" + GET_RESPONSE); System.out.println(">>>" + response.getText()); @@ -93,6 +87,16 @@ public class CustomerServiceTestCase { Assert.assertEquals(GET_RESPONSE, response.getText()); } + + @Test + public void testGetInvocationNotFound() throws Exception { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(SERVICE_URL+"/Foo"); + request.setHeaderField("Content-Type", "application/xml"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(404, response.getResponseCode()); + } @Test public void testPutInvocation() throws Exception { diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java index 94ebc1e1b8..403804e95e 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java @@ -23,6 +23,8 @@ import javax.jws.WebResult; 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 javax.ws.rs.core.Response; import org.oasisopen.sca.annotation.Remotable; @@ -32,7 +34,8 @@ public interface CustomerService { @GET @WebResult(name = "Customer", targetNamespace = "") - Customer get(); + @Path("{name}") + Customer get(@PathParam("name") String name); @GET @WebResult(name = "Customer", targetNamespace = "") diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java index 22e63e0f91..d0f2809cd6 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java @@ -23,7 +23,9 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.oasisopen.sca.annotation.Init; import org.oasisopen.sca.annotation.Scope; @@ -37,21 +39,26 @@ public class CustomerServiceImpl implements CustomerService { customers.put("John", new Customer("John", "John", "john@domain.com")); } - public Customer get() { - return customers.values().iterator().next(); + public Customer get(String name) { + Customer c = customers.get(name); + if (c == null) { + // Not found + throw new WebApplicationException(Status.NOT_FOUND); + } + return c; } - + public Response getResponse() { - return Response.ok(get()).build(); + return Response.ok(get("John")).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) { + if (customers.get(customer.getName()) != null) { customers.put(customer.getName(), customer); } } |