KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > secure > noenv > TransportOptionsTestCase


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.secure.noenv;
23
24 import java.io.File JavaDoc;
25
26 import javax.naming.Context JavaDoc;
27 import javax.xml.rpc.Service JavaDoc;
28 import javax.xml.rpc.Stub JavaDoc;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32
33 import org.jboss.test.JBossTestCase;
34 import org.jboss.test.webservice.WebserviceTestBase;
35 import org.jboss.test.webservice.ws4eesimple.HelloWs;
36
37 /**
38  * Tests SSL transport options
39  *
40  * @author <a HREF="mailto:jason.greene@jboss.com">Jason T. Greene</a>
41  */

42 public class TransportOptionsTestCase extends WebserviceTestBase
43 {
44    public TransportOptionsTestCase(String JavaDoc name)
45    {
46       super(name);
47    }
48
49    public static Test suite() throws Exception JavaDoc
50    {
51       // JBAS-3610, the execution order of tests in this test case is important
52
// so it must be defined explicitly when running under some JVMs
53
TestSuite suite = new TestSuite();
54       suite.addTest(new TransportOptionsTestCase("testWithTransportOptions"));
55       suite.addTest(new TransportOptionsTestCase("testWithoutKeystore"));
56       
57       return JBossTestCase.getDeploySetup(suite, "ws4ee-simple-secure.war, ws4ee-simple-secure-client.jar");
58    }
59
60
61    public void testWithTransportOptions() throws Exception JavaDoc
62    {
63       Context JavaDoc envCtx = getClientContext();
64       Service JavaDoc service = (Service JavaDoc)envCtx.lookup("java:comp/env/service/HelloWsSecureService");
65       HelloWs port = (HelloWs)service.getPort(HelloWs.class);
66
67       String JavaDoc keyStore = "resources/test-configs/webservice-ssl/conf/client.keystore";
68       assertTrue("Keystore exists", new File JavaDoc(keyStore).exists());
69
70       Stub JavaDoc stub = (Stub JavaDoc)port;
71       if (isWS4EEAvailable())
72       {
73          stub._setProperty("org.jboss.webservice.keyStore", keyStore);
74          stub._setProperty("org.jboss.webservice.keyStorePassword", "unit-tests-client");
75          stub._setProperty("org.jboss.webservice.keyStoreType", "JKS");
76          stub._setProperty("org.jboss.webservice.trustStore", keyStore);
77          stub._setProperty("org.jboss.webservice.trustStorePassword", "unit-tests-client");
78          stub._setProperty("org.jboss.webservice.trustStoreType", "JKS");
79       }
80       if (isJBossWSAvailable())
81       {
82          stub._setProperty("org.jboss.ws.keyStore", keyStore);
83          stub._setProperty("org.jboss.ws.keyStorePassword", "unit-tests-client");
84          stub._setProperty("org.jboss.ws.keyStoreType", "JKS");
85          stub._setProperty("org.jboss.ws.trustStore", keyStore);
86          stub._setProperty("org.jboss.ws.trustStorePassword", "unit-tests-client");
87          stub._setProperty("org.jboss.ws.trustStoreType", "JKS");
88       }
89
90       String JavaDoc res = port.sayHello("Hello");
91       assertEquals("'Hello' to you too!", res);
92
93       res = port.sayHello("Hello2");
94       assertEquals("'Hello2' to you too!", res);
95    }
96
97    public void testWithoutKeystore() throws Exception JavaDoc
98    {
99       Context JavaDoc envCtx = getClientContext();
100       Service JavaDoc service = (Service JavaDoc)envCtx.lookup("java:comp/env/service/HelloWsSecureService");
101       HelloWs port = (HelloWs)service.getPort(HelloWs.class);
102
103       String JavaDoc keyStore = "resources/test-configs/webservice-ssl/conf/client.keystore";
104       assertTrue("Keystore exists", new File JavaDoc(keyStore).exists());
105
106       Stub JavaDoc stub = (Stub JavaDoc)port;
107       if (isWS4EEAvailable())
108       {
109          stub._setProperty("org.jboss.webservice.trustStore", keyStore);
110          stub._setProperty("org.jboss.webservice.trustStorePassword", "unit-tests-client");
111          stub._setProperty("org.jboss.webservice.trustStoreType", "JKS");
112       }
113       if (isJBossWSAvailable())
114       {
115          stub._setProperty("org.jboss.ws.trustStore", keyStore);
116          stub._setProperty("org.jboss.ws.trustStorePassword", "unit-tests-client");
117          stub._setProperty("org.jboss.ws.trustStoreType", "JKS");
118       }
119
120       try
121       {
122          String JavaDoc res = port.sayHello("Hello");
123          System.out.println("FIXME: JBWS-777");
124          //fail("Expected security exception");
125
}
126       catch (Exception JavaDoc e)
127       {
128          //ignore
129
}
130    }
131 }
132
Popular Tags