Source Code Cross Referenced for CertificateMessageTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » xnet » provider » jsse » 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 » Apache Harmony Java SE » org package » org.apache.harmony.xnet.provider.jsse 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.xnet.provider.jsse;
019:
020:        import java.io.ByteArrayInputStream;
021:        import java.io.IOException;
022:        import java.security.cert.CertificateEncodingException;
023:        import java.security.cert.CertificateException;
024:        import java.security.cert.CertificateFactory;
025:        import java.security.cert.X509Certificate;
026:        import java.util.Arrays;
027:
028:        import junit.framework.TestCase;
029:
030:        /**
031:         * Tests for <code>CertificateMessage</code> constructor and methods
032:         *  
033:         */
034:        public class CertificateMessageTest extends TestCase {
035:
036:            private static String base64certEncoding = "-----BEGIN CERTIFICATE-----\n"
037:                    + "MIIC+jCCAragAwIBAgICAiswDAYHKoZIzjgEAwEBADAdMRswGQYDVQQKExJDZXJ0a"
038:                    + "WZpY2F0ZSBJc3N1ZXIwIhgPMTk3MDAxMTIxMzQ2NDBaGA8xOTcwMDEyNDAzMzMyMF"
039:                    + "owHzEdMBsGA1UEChMUU3ViamVjdCBPcmdhbml6YXRpb24wGTAMBgcqhkjOOAQDAQE"
040:                    + "AAwkAAQIDBAUGBwiBAgCqggIAVaOCAhQwggIQMA8GA1UdDwEB/wQFAwMBqoAwEgYD"
041:                    + "VR0TAQH/BAgwBgEB/wIBBTAUBgNVHSABAf8ECjAIMAYGBFUdIAAwZwYDVR0RAQH/B"
042:                    + "F0wW4EMcmZjQDgyMi5OYW1lggdkTlNOYW1lpBcxFTATBgNVBAoTDE9yZ2FuaXphdG"
043:                    + "lvboYaaHR0cDovL3VuaWZvcm0uUmVzb3VyY2UuSWSHBP///wCIByoDolyDsgMwDAY"
044:                    + "DVR0eAQH/BAIwADAMBgNVHSQBAf8EAjAAMIGZBgNVHSUBAf8EgY4wgYsGBFUdJQAG"
045:                    + "CCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDB"
046:                    + "AYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEFBQcDBwYIKwYBBQUHAwgGCCsGAQUFBw"
047:                    + "MJBggrBgEFBQgCAgYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GA1UdNgEB/wQDAgE"
048:                    + "BMA4GBCpNhgkBAf8EAwEBATBkBgNVHRIEXTBbgQxyZmNAODIyLk5hbWWCB2ROU05h"
049:                    + "bWWkFzEVMBMGA1UEChMMT3JnYW5pemF0aW9uhhpodHRwOi8vdW5pZm9ybS5SZXNvd"
050:                    + "XJjZS5JZIcE////AIgHKgOiXIOyAzAJBgNVHR8EAjAAMAoGA1UdIwQDAQEBMAoGA1"
051:                    + "UdDgQDAQEBMAoGA1UdIQQDAQEBMAwGByqGSM44BAMBAQADMAAwLQIUAL4QvoazNWP"
052:                    + "7jrj84/GZlhm09DsCFQCBKGKCGbrP64VtUt4JPmLjW1VxQA==\n"
053:                    + "-----END CERTIFICATE-----\n";
054:
055:            /*
056:             * Test for CertificateMessage(null) and
057:             * CertificateMessage(HandshakeIODataStream, int)
058:             */
059:            public void testCertificateMessage1() throws Exception {
060:
061:                CertificateMessage message = new CertificateMessage(null);
062:                assertEquals("incorrect type", Handshake.CERTIFICATE, message
063:                        .getType());
064:                assertEquals("incorrect message", 3, message.length());
065:                assertEquals("incorrect message", 0, message.certs.length);
066:
067:                HandshakeIODataStream out = new HandshakeIODataStream();
068:                message.send(out);
069:                byte[] encoded = out.getData(1000);
070:                assertEquals("incorrect out data length", message.length(),
071:                        encoded.length);
072:
073:                HandshakeIODataStream in = new HandshakeIODataStream();
074:                in.append(encoded);
075:
076:                CertificateMessage message_2 = new CertificateMessage(in,
077:                        message.length());
078:                assertEquals("incorrect message_2", 3, message_2.length());
079:                assertEquals("incorrect message_2", 0, message_2.certs.length);
080:            }
081:
082:            /*
083:             * Test for void CertificateMessage(X509Certificate[]),
084:             * CertificateMessage(HandshakeIODataStream, int)
085:             */
086:            public void testCertificateMessage2() throws Exception {
087:                CertificateFactory certFactory = CertificateFactory
088:                        .getInstance("X509");
089:
090:                ByteArrayInputStream bais = new ByteArrayInputStream(
091:                        base64certEncoding.getBytes());
092:                X509Certificate cert = (X509Certificate) certFactory
093:                        .generateCertificate(bais);
094:                CertificateMessage message = new CertificateMessage(
095:                        new X509Certificate[] { cert });
096:                assertEquals("incorrect type", Handshake.CERTIFICATE, message
097:                        .getType());
098:
099:                assertTrue("incorrect cert encoding", Arrays.equals(
100:                        message.certs[0].getEncoded(), cert.getEncoded()));
101:
102:                HandshakeIODataStream out = new HandshakeIODataStream();
103:                message.send(out);
104:                byte[] encoded = out.getData(1000);
105:                assertEquals("incorrect out data length", message.length(),
106:                        encoded.length);
107:
108:                HandshakeIODataStream in = new HandshakeIODataStream();
109:                in.append(encoded);
110:                CertificateMessage message_2 = new CertificateMessage(in,
111:                        message.length());
112:                assertEquals("Incorrect message decoding",
113:                        message.certs.length, message_2.certs.length);
114:                assertTrue("incorrect cert encoding", Arrays.equals(
115:                        message.certs[0].getEncoded(), message_2.certs[0]
116:                                .getEncoded()));
117:
118:                in.append(encoded);
119:                try {
120:                    message_2 = new CertificateMessage(in, message.length() - 1);
121:                    fail("Small length: No expected AlertException");
122:                } catch (AlertException e) {
123:                }
124:
125:                in.append(encoded);
126:                in.append(new byte[] { 1, 2, 3 });
127:                try {
128:                    message_2 = new CertificateMessage(in, message.length() + 3);
129:                    fail("Extra bytes: No expected AlertException ");
130:                } catch (AlertException e) {
131:                }
132:            }
133:
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.