KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > samples2 > OrderProcessRPCTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
29 import javax.xml.rpc.Service JavaDoc;
30
31 /**
32  * Test access to a complex rpc/literal endpoint
33  *
34  * @author Thomas.Diesler@jboss.org
35  * @since 26-Apr-2004
36  */

37 public class OrderProcessRPCTestCase extends WebserviceTestBase
38 {
39
40    public OrderProcessRPCTestCase(String JavaDoc name)
41    {
42       super(name);
43    }
44
45    /** Deploy the test */
46    public static Test suite() throws Exception JavaDoc
47    {
48       return getDeploySetup(OrderProcessRPCTestCase.class, "ws4ee-samples2-rpc.war, ws4ee-samples2-rpc-client.jar");
49    }
50
51    /** Test a valid access */
52    public void testValidAccess() throws Exception JavaDoc
53    {
54       InitialContext JavaDoc iniCtx = getClientContext();
55       Service JavaDoc service = (Service JavaDoc)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    /** Test a valid access */
72    public void testNullPerson() throws Exception JavaDoc
73    {
74       InitialContext JavaDoc iniCtx = getClientContext();
75       Service JavaDoc service = (Service JavaDoc)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          // ignore expected exception
90
}
91    }
92
93    /** Test a valid access */
94    public void testTooManyItems() throws Exception JavaDoc
95    {
96       InitialContext JavaDoc iniCtx = getClientContext();
97       Service JavaDoc service = (Service JavaDoc)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          // ignore expected exception
114
}
115    }
116 }
117
Popular Tags