Source Code Cross Referenced for KeyStoreSpiTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » tests » java » security » 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.security.tests.java.security 
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:        /**
019:         * @author Vera Y. Petrashkova
020:         * @version $Revision$
021:         */package org.apache.harmony.security.tests.java.security;
022:
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.security.KeyStore;
026:        import java.security.KeyStoreException;
027:        import java.security.KeyStoreSpi;
028:        import java.security.NoSuchAlgorithmException;
029:        import java.security.UnrecoverableEntryException;
030:        import java.security.UnrecoverableKeyException;
031:        import java.security.cert.Certificate;
032:        import java.security.cert.CertificateException;
033:        import java.util.Date;
034:
035:        import junit.framework.TestCase;
036:
037:        import org.apache.harmony.security.tests.support.MyKeyStoreSpi;
038:        import org.apache.harmony.security.tests.support.MyLoadStoreParams;
039:        import org.apache.harmony.security.tests.support.cert.MyCertificate;
040:
041:        /**
042:         * Tests for <code>KeyStoreSpi</code> constructor and methods
043:         * 
044:         */
045:
046:        public class KeyStoreSpiTest extends TestCase {
047:
048:            /**
049:             * Constructor for KeyStoreSpi.
050:             * 
051:             * @param arg0
052:             */
053:            public KeyStoreSpiTest(String arg0) {
054:                super (arg0);
055:            }
056:
057:            /**
058:             * Test for <code>KeyStoreSpi()</code> constructor 
059:             * and the following methods: 
060:             * <code>engineLoad(KeyStore.LoadStoreParameter param)</code>
061:             * <code>engineStore(KeyStore.LoadStoreParameter param)</code>
062:             * <code>engineGetEntry(String alias, KeyStore.ProtectionParameter param)</code>
063:             * <code>engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter param)</code>
064:             * Assertions: 
065:             * creates new KeyStoreSpi object;
066:             * engineGetEntry(..) returns null entry;
067:             * engineStore(..) throws UnexpectedOperationException;
068:             * engineSetEntry(..) throws KeyStoreException or NullPointerException 
069:             */
070:            public void testKeyStoteSpi01() throws IOException,
071:                    NoSuchAlgorithmException, CertificateException,
072:                    UnrecoverableEntryException, KeyStoreException {
073:                KeyStoreSpi ksSpi = new MyKeyStoreSpi();
074:
075:                tmpEntry entry = new tmpEntry();
076:                tmpProtection pPar = new tmpProtection();
077:
078:                try {
079:                    ksSpi.engineStore(null);
080:                } catch (UnsupportedOperationException e) {
081:                }
082:                assertNull("Not null entry", ksSpi.engineGetEntry("aaa", null));
083:                assertNull("Not null entry", ksSpi.engineGetEntry(null, pPar));
084:                assertNull("Not null entry", ksSpi.engineGetEntry("aaa", pPar));
085:
086:                try {
087:                    ksSpi.engineSetEntry("", null, null);
088:                    fail("KeyStoreException or NullPointerException must be thrown");
089:                } catch (KeyStoreException e) {
090:                } catch (NullPointerException e) {
091:                }
092:
093:                try {
094:                    ksSpi.engineSetEntry("",
095:                            new KeyStore.TrustedCertificateEntry(
096:                                    new MyCertificate("type", new byte[0])),
097:                            null);
098:                    fail("KeyStoreException must be thrown");
099:                } catch (KeyStoreException e) {
100:                }
101:
102:                try {
103:                    ksSpi.engineSetEntry("aaa", entry, null);
104:                    fail("KeyStoreException must be thrown");
105:                } catch (KeyStoreException e) {
106:                }
107:            }
108:
109:            /**
110:             * Test for <code>KeyStoreSpi()</code> constructor 
111:             * and abstract engine methods.
112:             * Assertion: creates new KeyStoreSpi object.
113:             */
114:            public void testKeyStoteSpi02() throws NoSuchAlgorithmException,
115:                    UnrecoverableKeyException, CertificateException {
116:                KeyStoreSpi ksSpi = new MyKeyStoreSpi();
117:                assertNull("engineGetKey(..) must return null", ksSpi
118:                        .engineGetKey("", new char[0]));
119:                assertNull("engineGetCertificateChain(..) must return null",
120:                        ksSpi.engineGetCertificateChain(""));
121:                assertNull("engineGetCertificate(..) must return null", ksSpi
122:                        .engineGetCertificate(""));
123:                assertEquals("engineGetCreationDate(..) must return Date(0)",
124:                        new Date(0), ksSpi.engineGetCreationDate(""));
125:                try {
126:                    ksSpi.engineSetKeyEntry("", null, new char[0],
127:                            new Certificate[0]);
128:                    fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
129:                } catch (KeyStoreException e) {
130:                }
131:                try {
132:                    ksSpi
133:                            .engineSetKeyEntry("", new byte[0],
134:                                    new Certificate[0]);
135:                    fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
136:                } catch (KeyStoreException e) {
137:                }
138:                try {
139:                    ksSpi.engineSetCertificateEntry("", null);
140:                    fail("KeyStoreException must be thrown from engineSetCertificateEntry(..)");
141:                } catch (KeyStoreException e) {
142:                }
143:                try {
144:                    ksSpi.engineDeleteEntry("");
145:                    fail("KeyStoreException must be thrown from engineDeleteEntry(..)");
146:                } catch (KeyStoreException e) {
147:                }
148:                assertNull("engineAliases() must return null", ksSpi
149:                        .engineAliases());
150:                assertFalse("engineContainsAlias(..) must return false", ksSpi
151:                        .engineContainsAlias(""));
152:                assertEquals("engineSize() must return 0", 0, ksSpi
153:                        .engineSize());
154:                try {
155:                    ksSpi.engineStore(null, null);
156:                    fail("IOException must be thrown");
157:                } catch (IOException e) {
158:                }
159:            }
160:
161:            /**
162:             * @tests java.security.KeyStoreSpi#engineLoad(KeyStore.LoadStoreParameter)
163:             */
164:            public void test_engineLoadLjava_security_KeyStore_LoadStoreParameter()
165:                    throws Exception {
166:
167:                final String msg = "error";
168:
169:                KeyStoreSpi ksSpi = new MyKeyStoreSpi() {
170:                    public void engineLoad(InputStream stream, char[] password) {
171:                        assertNull(stream);
172:                        assertNull(password);
173:                        throw new RuntimeException(msg);
174:                    }
175:                };
176:                try {
177:                    ksSpi.engineLoad(null);
178:                    fail("Should throw exception");
179:                } catch (RuntimeException e) {
180:                    assertSame(msg, e.getMessage());
181:                }
182:
183:                // test: protection parameter is null  
184:                try {
185:                    ksSpi.engineLoad(new MyLoadStoreParams(null));
186:                    fail("No expected UnsupportedOperationException");
187:                } catch (UnsupportedOperationException e) {
188:                }
189:
190:                // test: protection parameter is not instanceof 
191:                // PasswordProtection or CallbackHandlerProtection
192:                try {
193:                    ksSpi
194:                            .engineLoad(new MyLoadStoreParams(
195:                                    new tmpProtection()));
196:                    fail("No expected UnsupportedOperationException");
197:                } catch (UnsupportedOperationException e) {
198:                }
199:            }
200:
201:            public static void main(String args[]) {
202:                junit.textui.TestRunner.run(KeyStoreSpiTest.class);
203:            }
204:        }
205:
206:        /**
207:         * Additional class implements KeyStore.Entry interface
208:         */
209:        class tmpEntry implements  KeyStore.Entry {
210:        }
211:
212:        class tmpProtection implements  KeyStore.ProtectionParameter {
213:        }
w__w__w__.j__a___v__a2_s.___c___om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.