KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > secure > ws4eesimple > SimpleClientSecureTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.webservice.secure.ws4eesimple;
8
9 // $Id: SimpleClientSecureTestCase.java,v 1.1.2.2 2005/06/15 01:47:18 jgreene Exp $
10

11 import javax.naming.Context JavaDoc;
12 import javax.xml.rpc.Service JavaDoc;
13
14 import junit.framework.Test;
15
16 import org.jboss.test.webservice.WebserviceTestBase;
17 import org.jboss.test.webservice.ws4eesimple.HelloWs;
18 import org.jboss.webservice.client.CallImpl;
19 import org.jboss.webservice.client.Stub;
20
21 /**
22  * Tests of the ws4ee functionality for a simple Hello EJB.
23  *
24  * @author Thomas.Diesler@jboss.org
25  * @author Christoph.Jung@infor.de
26  * @since 06-May-2004
27  */

28 public class SimpleClientSecureTestCase extends WebserviceTestBase
29 {
30
31    /**
32     * Construct the test case with a given name
33     */

34    public SimpleClientSecureTestCase(String JavaDoc name)
35    {
36       super(name);
37    }
38
39    /**
40     * deploy the test archives
41     */

42    public static Test suite() throws Exception JavaDoc
43    {
44       return getDeploySetup(SimpleClientSecureTestCase.class, "ws4ee-simple-secure.war, ws4ee-simple-secure-client.jar");
45    }
46
47    /**
48     * Test client application access
49     */

50    public void testWithTransportOptions() throws Exception JavaDoc
51    {
52       Context JavaDoc envCtx = getClientContext();
53       Object JavaDoc obj = envCtx.lookup("java:comp/env/service/HelloWsSecureService");
54       assertTrue("Is not a javax.xml.rpc.Service, but: " + obj, javax.xml.rpc.Service JavaDoc.class.isAssignableFrom(obj.getClass()));
55       Service JavaDoc service = (Service JavaDoc)obj;
56       HelloWs ws = (HelloWs)service.getPort(HelloWs.class);
57       Stub stub = (Stub)ws;
58
59       String JavaDoc root = System.getProperty("rootDir");
60       if (root == null)
61          root = "";
62       else
63          root += "/";
64
65       stub.setTransportOption("keyStore", root + "test-configs/webservice-ssl/conf/client.keystore");
66       stub.setTransportOption("keyStorePassword", "unit-tests-client");
67       stub.setTransportOption("keyStoreType", "JKS");
68       stub.setTransportOption("trustStore", root + "test-configs/webservice-ssl/conf/client.keystore");
69       stub.setTransportOption("trustStorePassword", "unit-tests-client");
70       stub.setTransportOption("trustStoreType", "JKS");
71
72       String JavaDoc res = ws.sayHello("Hello");
73       assertEquals("'Hello' to you too!", res);
74    }
75
76    public void testWithoutTransportOptions() throws Exception JavaDoc
77    {
78       Context JavaDoc envCtx = getClientContext();
79       Object JavaDoc obj = envCtx.lookup("java:comp/env/service/HelloWsSecureService");
80       assertTrue("Is not a javax.xml.rpc.Service, but: " + obj, javax.xml.rpc.Service JavaDoc.class.isAssignableFrom(obj.getClass()));
81       Service JavaDoc service = (Service JavaDoc)obj;
82       HelloWs ws = (HelloWs)service.getPort(HelloWs.class);
83
84       String JavaDoc res = ws.sayHello("Hello");
85       assertEquals("'Hello' to you too!", res);
86    }
87 }
88
Popular Tags