Source Code Cross Referenced for AlgorithmParameterGenerator3Test.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:        package org.apache.harmony.security.tests.java.security;
019:
020:        import java.math.BigInteger;
021:        import java.security.AlgorithmParameterGenerator;
022:        import java.security.AlgorithmParameters;
023:        import java.security.InvalidAlgorithmParameterException;
024:        import java.security.NoSuchProviderException;
025:        import java.security.Provider;
026:        import java.security.SecureRandom;
027:        import java.security.Security;
028:        import java.security.spec.DSAParameterSpec;
029:
030:        public class AlgorithmParameterGenerator3Test extends
031:                junit.framework.TestCase {
032:
033:            /**
034:             * @tests java.security.AlgorithmParameterGenerator#generateParameters()
035:             */
036:            public void test_generateParameters() throws Exception {
037:
038:                //fail("Takes ages. Problem with SecureRandom and stub math ?");
039:
040:                // Test for method java.security.AlgorithmParameters
041:                // java.security.AlgorithmParameterGenerator.generateParameters()
042:                AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
043:                        .getInstance("DSA");
044:                gen.init(1024);
045:
046:                // WARNING - The next line can take MINUTES to run
047:                AlgorithmParameters params = gen.generateParameters();
048:                assertNotNull("params is null", params);
049:            }
050:
051:            /**
052:             * @tests java.security.AlgorithmParameterGenerator#getAlgorithm()
053:             */
054:            public void test_getAlgorithm() throws Exception {
055:                // Test for method java.lang.String
056:                // java.security.AlgorithmParameterGenerator.getAlgorithm()
057:                String alg = AlgorithmParameterGenerator.getInstance("DSA")
058:                        .getAlgorithm();
059:                assertEquals("getAlgorithm ok", "DSA", alg);
060:            }
061:
062:            /**
063:             * @tests java.security.AlgorithmParameterGenerator#getInstance(java.lang.String)
064:             */
065:            public void test_getInstanceLjava_lang_String() throws Exception {
066:                // Test for method java.security.AlgorithmParameterGenerator
067:                // java.security.AlgorithmParameterGenerator.getInstance(java.lang.String)
068:                AlgorithmParameterGenerator.getInstance("DSA");
069:            }
070:
071:            /**
072:             * @tests java.security.AlgorithmParameterGenerator#getInstance(java.lang.String,
073:             *        java.lang.String)
074:             */
075:            public void test_getInstanceLjava_lang_StringLjava_lang_String()
076:                    throws Exception {
077:                // Test for method java.security.AlgorithmParameterGenerator
078:                // java.security.AlgorithmParameterGenerator.getInstance(java.lang.String,
079:                // java.lang.String)
080:
081:                // Opting for DSA here as it is pretty widely supported
082:                Provider[] provs = Security
083:                        .getProviders("AlgorithmParameterGenerator.DSA");
084:
085:                for (int i = 0; i < provs.length; i++) {
086:                    AlgorithmParameterGenerator.getInstance("DSA", provs[i]
087:                            .getName());
088:                }// end for
089:
090:                // exception case - should throw IllegalArgumentException for null
091:                // provider
092:                try {
093:                    AlgorithmParameterGenerator.getInstance("DSA",
094:                            (String) null);
095:                    fail("Should have thrown IllegalArgumentException");
096:                } catch (IllegalArgumentException e) {
097:                    // Expected
098:                }
099:
100:                // exception case - should throw IllegalArgumentException for empty
101:                // provider
102:                try {
103:                    AlgorithmParameterGenerator.getInstance("DSA", "");
104:                    fail("Should have thrown IllegalArgumentException");
105:                } catch (IllegalArgumentException e) {
106:                    // Expected
107:                }
108:
109:                // exception case - should throw NoSuchProviderException
110:                try {
111:                    AlgorithmParameterGenerator
112:                            .getInstance("DSA", "IDontExist");
113:                    fail("Should have thrown NoSuchProviderException");
114:                } catch (NoSuchProviderException e) {
115:                    // Expected
116:                }
117:            }
118:
119:            /**
120:             * @tests java.security.AlgorithmParameterGenerator#getProvider()
121:             */
122:            public void test_getProvider() throws Exception {
123:                // Test for method java.security.Provider
124:                // java.security.AlgorithmParameterGenerator.getProvider()
125:                // checks that no exception is thrown
126:                Provider p = AlgorithmParameterGenerator.getInstance("DSA")
127:                        .getProvider();
128:                assertNotNull("provider is null", p);
129:            }
130:
131:            /**
132:             * @tests java.security.AlgorithmParameterGenerator#init(int)
133:             */
134:            public void test_initI() throws Exception {
135:                // Test for method void
136:                // java.security.AlgorithmParameterGenerator.init(int)
137:                // checks that no exception is thrown
138:                AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
139:                        .getInstance("DSA");
140:                gen.init(1024);
141:            }
142:
143:            /**
144:             * @tests java.security.AlgorithmParameterGenerator#init(int,
145:             *        java.security.SecureRandom)
146:             */
147:            public void test_initILjava_security_SecureRandom()
148:                    throws Exception {
149:                // Test for method void
150:                // java.security.AlgorithmParameterGenerator.init(int,
151:                // java.security.SecureRandom)
152:                // checks that no exception is thrown
153:                AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
154:                        .getInstance("DSA");
155:                gen.init(1024, new SecureRandom());
156:            }
157:
158:            /**
159:             * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec)
160:             */
161:            public void test_initLjava_security_spec_AlgorithmParameterSpec()
162:                    throws Exception {
163:                // Test for method void
164:                // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec)
165:                // checks that InvalidAlgorithmParameterException is thrown
166:                DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
167:                        BigInteger.ONE, BigInteger.ONE);
168:                AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
169:                        .getInstance("DSA");
170:                try {
171:                    gen.init(spec);
172:                    fail("No expected InvalidAlgorithmParameterException");
173:                } catch (InvalidAlgorithmParameterException e) {
174:                    //expected
175:                }
176:            }
177:
178:            /**
179:             * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec,
180:             *        java.security.SecureRandom)
181:             */
182:            public void test_initLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
183:                    throws Exception {
184:                // Test for method void
185:                // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec,
186:                // java.security.SecureRandom)
187:                // checks that InvalidAlgorithmParameterException  is thrown
188:                DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
189:                        BigInteger.ONE, BigInteger.ONE);
190:                AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
191:                        .getInstance("DSA");
192:                try {
193:                    gen.init(spec, new SecureRandom());
194:                    fail("No expected InvalidAlgorithmParameterException");
195:                } catch (InvalidAlgorithmParameterException e) {
196:                    //expected
197:                }
198:            }
199:        }
w_w__w_.___j___a_v___a_2s._c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.