~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/socket/ssl/serversocketrefresh/TestClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jboss.test.remoting.transport.socket.ssl.serversocketrefresh;
 
2
 
 
3
import junit.framework.TestCase;
 
4
 
 
5
import org.jboss.logging.Logger;
 
6
import org.jboss.remoting.Client;
 
7
import org.jboss.remoting.InvokerLocator;
 
8
import org.jboss.remoting.security.SSLSocketBuilder;
 
9
 
 
10
import java.util.HashMap;
 
11
import java.util.Map;
 
12
 
 
13
/**
 
14
 * @author Michael Voss
 
15
 *
 
16
 */
 
17
public class TestClient extends TestCase{
 
18
        private static Logger log = Logger.getLogger(TestClient.class);
 
19
        private String keyStorePath="src/tests/org/jboss/test/remoting/transport/socket/ssl/serversocketrefresh/certificate/clientKeyStore";
 
20
        private String trustStorePath="src/tests/org/jboss/test/remoting/transport/socket/ssl/serversocketrefresh/certificate/clientTrustStore";
 
21
        private String keyStorePassword="testpw";
 
22
        private String trustStorePassword="testpw";
 
23
        InvokerLocator locator;
 
24
        Client client;
 
25
        Map configuration;
 
26
        
 
27
        public void setUp() throws Exception{
 
28
       log.info("entering setUp()");
 
29
                locator=new InvokerLocator(getTransport() + "://localHost:2001");
 
30
                
 
31
                //the client side connection endpoint
 
32
                configuration = new HashMap();
 
33
 
 
34
      //String keyStorePath = this.getClass().getResource("certificate/serverKeyStore").getFile();
 
35
      //String trustStorePath = this.getClass().getResource("certificate/serverTrustStore").getFile();
 
36
                String keyStorePath = this.getClass().getResource("certificate/clientKeyStore").getFile();
 
37
            String trustStorePath = this.getClass().getResource("certificate/clientTrustStore").getFile();
 
38
 
 
39
        configuration.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
 
40
                configuration.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStorePath);
 
41
                configuration.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, keyStorePassword);
 
42
                configuration.put(SSLSocketBuilder.REMOTING_KEY_STORE_ALGORITHM, "SunX509");
 
43
                
 
44
                configuration.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
 
45
                configuration.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStorePath);
 
46
                configuration.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, trustStorePassword);
 
47
                configuration.put(SSLSocketBuilder.REMOTING_TRUST_STORE_ALGORITHM, "SunX509");
 
48
                
 
49
                client=new Client(locator,"Sample",configuration);                              
 
50
                
 
51
                client.connect();
 
52
        log.info("leaving setUp()");
 
53
                
 
54
        }
 
55
        
 
56
        public void tearDown() throws Exception{
 
57
       log.info("entering tearDown()");
 
58
                Thread.sleep(10000);//let the server fetch his new truststore and refresh serversocket
 
59
                log.info("finished first sleep in tearDown()");
 
60
        client.disconnect();
 
61
        log.info("disconnected client in tearDown()");
 
62
                Thread.sleep(350000);
 
63
        log.info("finished second sleep in tearDown()");
 
64
 
 
65
                try {
 
66
            setUp();//secondPass -> client is not accepted by new truststore
 
67
                        test();//secondPass -> client is not accepted by new truststore
 
68
                } catch (Throwable e) {
 
69
           log.error("expected Exception", e);
 
70
                        client.disconnect();
 
71
            log.info("SUCCESS");
 
72
                        return;
 
73
                }
 
74
                client.disconnect();
 
75
                throw new Exception("should not reach this point");//because client should not be accepted by new server truststore
 
76
                
 
77
        }
 
78
        
 
79
        /**
 
80
         * @throws Throwable
 
81
         */
 
82
        public void test() throws Throwable{
 
83
                log.info("Invoking server with 'something'");
 
84
                log.info("Server answer is: "+client.invoke("something"));
 
85
        }
 
86
        
 
87
        protected String getTransport()
 
88
        {
 
89
           return "sslsocket";
 
90
        }
 
91
        
 
92
}