Source Code Cross Referenced for JettySslClientSystemPropertiesConfigurerTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » bus » transports » https » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » celtix 1.0 » org.objectweb.celtix.bus.transports.https 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.bus.transports.https;
002:
003:        import java.net.URL;
004:        import java.net.URLConnection;
005:        import java.util.Properties;
006:
007:        import javax.net.ssl.SSLSocketFactory;
008:
009:        import junit.extensions.TestSetup;
010:        import junit.framework.Test;
011:        import junit.framework.TestCase;
012:        import junit.framework.TestSuite;
013:
014:        import org.easymock.classextension.EasyMock;
015:        import org.objectweb.celtix.Bus;
016:        import org.objectweb.celtix.BusException;
017:        import org.objectweb.celtix.bus.configuration.security.SSLClientPolicy;
018:        import org.objectweb.celtix.configuration.Configuration;
019:
020:        public class JettySslClientSystemPropertiesConfigurerTest extends
021:                TestCase {
022:
023:            private static final String DROP_BACK_SRC_DIR = "../../../../../../../../src/test/java/org/objectweb/celtix/bus/transports/https/";
024:
025:            Bus bus;
026:
027:            public JettySslClientSystemPropertiesConfigurerTest(String arg0) {
028:                super (arg0);
029:            }
030:
031:            public static Test suite() throws Exception {
032:                TestSuite suite = new TestSuite(
033:                        JettySslClientSystemPropertiesConfigurerTest.class);
034:                return new TestSetup(suite) {
035:                    protected void tearDown() throws Exception {
036:                        super .tearDown();
037:                    }
038:                };
039:            }
040:
041:            public static void main(String[] args) {
042:                junit.textui.TestRunner
043:                        .run(JettySslClientSystemPropertiesConfigurerTest.class);
044:            }
045:
046:            public void setUp() throws BusException {
047:                bus = EasyMock.createMock(Bus.class);
048:            }
049:
050:            public void tearDown() throws Exception {
051:                EasyMock.reset(bus);
052:                Properties props = System.getProperties();
053:                props.remove("javax.net.ssl.trustStore");
054:                props.remove("javax.net.ssl.keyStore");
055:                props.remove("javax.net.ssl.keyPassword");
056:                props.remove("javax.net.ssl.keyStorePassword");
057:            }
058:
059:            public void testSetAllDataSomeSystemProperties() {
060:
061:                String keyStoreStr = getPath("resources/defaultkeystore");
062:                SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
063:                System.setProperty("javax.net.ssl.keyStore", keyStoreStr);
064:                sslClientPolicy.setKeystoreType("JKS");
065:
066:                System.setProperty("javax.net.ssl.keyStorePassword",
067:                        "defaultkeypass");
068:                System.setProperty("javax.net.ssl.keyPassword",
069:                        "defaultkeypass");
070:                sslClientPolicy.setTrustStoreType("JKS");
071:                sslClientPolicy.setTrustStoreAlgorithm("JKS");
072:                sslClientPolicy.setSecureSocketProtocol("TLSv1");
073:                sslClientPolicy.setSessionCacheKey("Anything");
074:                sslClientPolicy.setSessionCaching(true);
075:                sslClientPolicy.setMaxChainLength(new Long(2));
076:                sslClientPolicy.setCertValidator("Anything");
077:                sslClientPolicy.setProxyHost("Anything");
078:                sslClientPolicy.setProxyPort(new Long(1234));
079:
080:                String trustStoreStr = getPath("resources/defaulttruststore");
081:                System.setProperty("javax.net.ssl.trustStore", trustStoreStr);
082:                TestHandler handler = new TestHandler();
083:                JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
084:                        sslClientPolicy, "https://dummyurl", handler);
085:
086:                jettySslClientConfigurer.configure();
087:                SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer
088:                        .getHttpsConnection().getSSLSocketFactory();
089:
090:                assertTrue("sSLSocketFactory not correct, sSLSocketFactory = "
091:                        + sSLSocketFactory,
092:                        sSLSocketFactory instanceof  SSLSocketFactoryWrapper);
093:                assertTrue(
094:                        "Keystore loaded success message not present",
095:                        handler
096:                                .checkLogContainsString("Successfully loaded keystore"));
097:                assertTrue(
098:                        "Trust store loaded success message not present",
099:                        handler
100:                                .checkLogContainsString("Successfully loaded trust store"));
101:                assertTrue(
102:                        "Keystore type not being read",
103:                        handler
104:                                .checkLogContainsString("The key store type has been set in configuration to JKS"));
105:                assertTrue(
106:                        "Keystore password not being read",
107:                        handler
108:                                .checkLogContainsString("The key store password was found to be set "
109:                                        + "as a system property and will be used."));
110:                assertTrue(
111:                        "Key password not being read",
112:                        handler
113:                                .checkLogContainsString("The key  password was found to be set as a "
114:                                        + "system property and will be used."));
115:                assertTrue(
116:                        "Key manager factory is being being read from somewhere unknown",
117:                        handler
118:                                .checkLogContainsString("The keystore key manager factory "
119:                                        + "algorithm has not been set in configuration "
120:                                        + "so the default value SunX509 will be used."));
121:
122:                assertTrue(
123:                        "Trust manager factory is being being read from somewhere unknown",
124:                        handler
125:                                .checkLogContainsString("The truststore key manager factory "
126:                                        + "algorithm has not been set in configuration "
127:                                        + "so the default value PKIX will be used."));
128:                assertTrue(
129:                        "Trust store location not read successfully",
130:                        handler
131:                                .checkLogContainsString("The trust store location has been "
132:                                        + "via a system property to"));
133:
134:                assertTrue(
135:                        "Ciphersuites is being being read from somewhere unknown",
136:                        handler
137:                                .checkLogContainsString("The cipher suite has not been set, default values "
138:                                        + "will be used."));
139:                assertTrue(
140:                        "Truststore type not being read",
141:                        handler
142:                                .checkLogContainsString("The key store type has been set in "
143:                                        + "configuration to JKS"));
144:
145:                assertTrue(
146:                        "Secure socket protocol not being read",
147:                        handler
148:                                .checkLogContainsString("The secure socket protocol has been set to TLSv1."));
149:                assertTrue(
150:                        "Session caching set but no warning about not supported",
151:                        handler
152:                                .checkLogContainsString("Unsupported SSLClientPolicy property : SessionCaching"));
153:                assertTrue(
154:                        "SessionCacheKey caching set but no warning about not supported",
155:                        handler
156:                                .checkLogContainsString("Unsupported SSLClientPolicy property : SessionCacheKey"));
157:                assertTrue(
158:                        "MaxChainLength caching set but no warning about not supported",
159:                        handler
160:                                .checkLogContainsString("Unsupported SSLClientPolicy property : MaxChainLength"));
161:                assertTrue(
162:                        "CertValidator caching set but no warning about not supported",
163:                        handler
164:                                .checkLogContainsString("Unsupported SSLClientPolicy property : CertValidator"));
165:            }
166:
167:            private JettySslClientConfigurer createJettySslClientConfigurer(
168:                    SSLClientPolicy sslClientPolicy, String urlStr,
169:                    TestHandler handler) {
170:                try {
171:                    URL url = new URL(urlStr);
172:                    URLConnection connection = new DummyHttpsConnection(url);
173:                    Configuration configuration = EasyMock
174:                            .createMock(Configuration.class);
175:                    JettySslClientConfigurer jettySslClientConfigurer = new JettySslClientConfigurer(
176:                            sslClientPolicy, connection, configuration);
177:
178:                    jettySslClientConfigurer.addLogHandler(handler);
179:                    return jettySslClientConfigurer;
180:
181:                } catch (Exception e) {
182:                    e.printStackTrace();
183:                }
184:                return null;
185:            }
186:
187:            private String getPath(String fileName) {
188:                URL keystoreURL = JettySslClientSystemPropertiesConfigurerTest.class
189:                        .getResource(".");
190:                String str = keystoreURL.getFile();
191:                str += DROP_BACK_SRC_DIR + fileName;
192:                return str;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.