1 22 package org.jboss.test.webservice.samples2; 23 24 25 import junit.framework.Test; 26 import org.jboss.test.webservice.WebserviceTestBase; 27 28 import javax.naming.InitialContext ; 29 import javax.xml.rpc.Service ; 30 31 37 public class OrderProcessRPCTestCase extends WebserviceTestBase 38 { 39 40 public OrderProcessRPCTestCase(String name) 41 { 42 super(name); 43 } 44 45 46 public static Test suite() throws Exception 47 { 48 return getDeploySetup(OrderProcessRPCTestCase.class, "ws4ee-samples2-rpc.war, ws4ee-samples2-rpc-client.jar"); 49 } 50 51 52 public void testValidAccess() throws Exception 53 { 54 InitialContext iniCtx = getClientContext(); 55 Service service = (Service )iniCtx.lookup("java:comp/env/service/OrderProcess"); 56 OrderProcess endpoint = (OrderProcess)service.getPort(OrderProcess.class); 57 58 Person p = new Person("Tom", 3); 59 OrderItem i0 = new OrderItem("Ferrari", 1); 60 OrderItem i1 = new OrderItem("Twix", 10); 61 OrderItem i2 = new OrderItem("IceCream", 3); 62 63 OrderResponse res = endpoint.processOrder(new OrderItem[]{i0, i1, i2}, p); 64 assertEquals(3, res.getItems().length); 65 assertEquals(i0, res.getItems()[0]); 66 assertEquals(i1, res.getItems()[1]); 67 assertEquals(i2, res.getItems()[2]); 68 assertEquals("approved", res.getMessage()); 69 } 70 71 72 public void testNullPerson() throws Exception 73 { 74 InitialContext iniCtx = getClientContext(); 75 Service service = (Service )iniCtx.lookup("java:comp/env/service/OrderProcess"); 76 OrderProcess endpoint = (OrderProcess)service.getPort(OrderProcess.class); 77 78 OrderItem i1 = new OrderItem("Ferrari", 1); 79 OrderItem i2 = new OrderItem("Twix", 10); 80 OrderItem i3 = new OrderItem("IceCream", 3); 81 82 try 83 { 84 endpoint.processOrder(new OrderItem[]{i1, i2, i3}, null); 85 fail("OrderException expected"); 86 } 87 catch (OrderException e) 88 { 89 } 91 } 92 93 94 public void testTooManyItems() throws Exception 95 { 96 InitialContext iniCtx = getClientContext(); 97 Service service = (Service )iniCtx.lookup("java:comp/env/service/OrderProcess"); 98 OrderProcess endpoint = (OrderProcess)service.getPort(OrderProcess.class); 99 100 Person p = new Person("Tom", 3); 101 OrderItem i1 = new OrderItem("Ferrari", 1); 102 OrderItem i2 = new OrderItem("Twix", 10); 103 OrderItem i3 = new OrderItem("IceCream", 3); 104 OrderItem i4 = new OrderItem("GameBoy", 1); 105 106 try 107 { 108 endpoint.processOrder(new OrderItem[]{i1, i2, i3, i4}, p); 109 fail("OrderException expected"); 110 } 111 catch (OrderException e) 112 { 113 } 115 } 116 } 117 | Popular Tags |