Source Code Cross Referenced for Provider2Test.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.security.MessageDigest;
021:        import java.security.NoSuchAlgorithmException;
022:        import java.security.Provider;
023:        import java.security.Security;
024:
025:        public class Provider2Test extends junit.framework.TestCase {
026:
027:            class TestProvider extends Provider {
028:                TestProvider(String name, double version, String info) {
029:                    super (name, version, info);
030:                }
031:            }
032:
033:            class MyEntry implements  java.util.Map.Entry {
034:                public Object getKey() {
035:                    return null;
036:                }
037:
038:                public Object getValue() {
039:                    return null;
040:                }
041:
042:                public Object setValue(Object value) {
043:                    return null;
044:                }
045:            }
046:
047:            TestProvider provTest = new TestProvider("provTest", 1.2,
048:                    "contains nothings, purely for testing the class");
049:
050:            /**
051:             * @tests java.security.Provider#entrySet()
052:             */
053:            public void test_entrySet() {
054:                // test method of java.security.provider.entrySet
055:                provTest.put("test.prop", "this is a test property");
056:                try {
057:                    //make it compilable on 1.5
058:                    provTest.entrySet().add(new MyEntry());
059:                    fail("was able to modify the entrySet");
060:                } catch (UnsupportedOperationException e) {
061:                    // expected
062:                }
063:            }
064:
065:            /**
066:             * @tests java.security.Provider#getInfo()
067:             */
068:            public void test_getInfo() {
069:                // test method of java.security.provider.getInfo
070:                assertEquals(
071:                        "the information of the provider is not stored properly",
072:                        "contains nothings, purely for testing the class",
073:                        provTest.getInfo());
074:            }
075:
076:            /**
077:             * @tests java.security.Provider#getName()
078:             */
079:            public void test_getName() {
080:                // test method of java.security.provider.getName
081:                assertEquals("the name of the provider is not stored properly",
082:                        "provTest", provTest.getName());
083:            }
084:
085:            /**
086:             * @tests java.security.Provider#getVersion()
087:             */
088:            public void test_getVersion() {
089:                // test method of java.security.provider.getVersion
090:                assertEquals(
091:                        "the version of the provider is not stored properly",
092:                        1.2, provTest.getVersion(), 0);
093:            }
094:
095:            /**
096:             * @tests java.security.Provider#keySet()
097:             */
098:            public void test_keySet() {
099:                // test method of java.security.provider.keySet
100:                provTest.put("test.prop", "this is a test property");
101:                try {
102:                    provTest.keySet().add("another property key");
103:                    fail("was able to modify the keySet");
104:                } catch (UnsupportedOperationException e) {
105:                    // expected
106:                }
107:            }
108:
109:            /**
110:             * @tests java.security.Provider#values()
111:             */
112:            public void test_values() {
113:                // test method of java.security.provider.values
114:                provTest.put("test.prop", "this is a test property");
115:                try {
116:                    provTest.values().add("another property value");
117:                    fail("was able to modify the values collection");
118:                } catch (UnsupportedOperationException e) {
119:                    // expected
120:                }
121:            }
122:
123:            /**
124:             * @tests java.security.Provider#toString()
125:             */
126:            public void test_toString() {
127:                // Regression for HARMONY-3734
128:                assertEquals("provTest version 1.2", provTest.toString());
129:            }
130:
131:            // Regression Test for Provider.Service.getAlias(), which is an package
132:            // private method but will lead to NPE thrown at
133:            // Secure.SecurityDorr.getAliases
134:            public void test_getAlias() throws Exception {
135:                MockProvider mockProvider = new MockProvider("MOCKNAME", 1.0,
136:                        "MOCKINFO");
137:                Provider.Service service = new Provider.Service(mockProvider,
138:                        "MOCKTYPE", "MOCKALGORITHM", "TESTCLASSNAME", null,
139:                        null);
140:                mockProvider.putService(service);
141:                Security.addProvider(mockProvider);
142:                try {
143:                    MessageDigest messageDigest = MessageDigest
144:                            .getInstance("NOTEXISTS");
145:                }
146:
147:                catch (NoSuchAlgorithmException e) {
148:                    // expected
149:                } finally {
150:                    Security.removeProvider("MOCKNAME");
151:                }
152:            }
153:
154:            public static class MockProvider extends Provider {
155:
156:                private static final long serialVersionUID = 1L;
157:
158:                public MockProvider(String name, double version, String info) {
159:                    super (name, version, info);
160:
161:                }
162:
163:                public void putService(Provider.Service service) {
164:                    super .putService(service);
165:                }
166:
167:                public void removeService(Provider.Service service) {
168:                    super.removeService(service);
169:                }
170:            }
171:        }
w___ww.__j_a__va2s___._c_o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.