KickJava   Java API By Example, From Geeks To Geeks.

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


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 import junit.framework.Test;
25 import org.jboss.test.webservice.WebserviceTestBase;
26
27 import javax.naming.InitialContext JavaDoc;
28 import javax.xml.rpc.Service JavaDoc;
29
30 /**
31  * Test access to a complex doc/literal endpoint
32  *
33  * @author Thomas.Diesler@jboss.org
34  * @since 26-Apr-2004
35  */

36 public class OrderProcessDOCBareTestCase extends WebserviceTestBase
37 {
38
39    public OrderProcessDOCBareTestCase(String JavaDoc name)
40    {
41       super(name);
42    }
43
44    /** Deploy the test */
45    public static Test suite() throws Exception JavaDoc
46    {
47       return getDeploySetup(OrderProcessDOCBareTestCase.class, "ws4ee-samples2-docbare.war, ws4ee-samples2-docbare-client.jar");
48    }
49
50    /** Test a valid access */
51    public void testValidAccess() throws Exception JavaDoc
52    {
53       InitialContext JavaDoc iniCtx = getClientContext();
54       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/OrderProcess");
55       OrderProcessBare endpoint = (OrderProcessBare)service.getPort(OrderProcessBare.class);
56
57       Person p = new Person("Tom", 3);
58       OrderItem i0 = new OrderItem("Ferrari", 1);
59       OrderItem i1 = new OrderItem("Twix", 10);
60       OrderItem i2 = new OrderItem("IceCream", 3);
61
62       OrderProcess_processOrder_RequestStruct reqStr = new OrderProcess_processOrder_RequestStruct(new OrderItem[] { i0, i1, i2 }, p);
63       OrderProcess_processOrder_ResponseStruct resStr = endpoint.processOrder(reqStr);
64       OrderResponse res = resStr.getResult();
65       assertEquals(3, res.getItems().length);
66       assertEquals(i0, res.getItems()[0]);
67       assertEquals(i1, res.getItems()[1]);
68       assertEquals(i2, res.getItems()[2]);
69       assertEquals("approved", res.getMessage());
70    }
71
72    /** Test a valid access */
73    public void testNullPerson() throws Exception JavaDoc
74    {
75       InitialContext JavaDoc iniCtx = getClientContext();
76       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/OrderProcess");
77       OrderProcessBare endpoint = (OrderProcessBare)service.getPort(OrderProcessBare.class);
78
79       OrderItem i1 = new OrderItem("Ferrari", 1);
80       OrderItem i2 = new OrderItem("Twix", 10);
81       OrderItem i3 = new OrderItem("IceCream", 3);
82
83       try
84       {
85          OrderProcess_processOrder_RequestStruct reqStr = new OrderProcess_processOrder_RequestStruct(new OrderItem[] { i1, i2, i3 }, null);
86          endpoint.processOrder(reqStr);
87          fail("OrderException expected");
88       }
89       catch (OrderException e)
90       {
91          // ignore expected exception
92
}
93    }
94
95    /** Test a valid access */
96    public void testTooManyItems() throws Exception JavaDoc
97    {
98       InitialContext JavaDoc iniCtx = getClientContext();
99       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/OrderProcess");
100       OrderProcessBare endpoint = (OrderProcessBare)service.getPort(OrderProcessBare.class);
101
102       Person p = new Person("Tom", 3);
103       OrderItem i1 = new OrderItem("Ferrari", 1);
104       OrderItem i2 = new OrderItem("Twix", 10);
105       OrderItem i3 = new OrderItem("IceCream", 3);
106       OrderItem i4 = new OrderItem("GameBoy", 1);
107
108       try
109       {
110          OrderProcess_processOrder_RequestStruct reqStr = new OrderProcess_processOrder_RequestStruct(new OrderItem[] { i1, i2, i3, i4 }, p);
111          endpoint.processOrder(reqStr);
112          fail("OrderException expected");
113       }
114       catch (OrderException e)
115       {
116          // ignore expected exception
117
}
118    }
119 }
120
Popular Tags