Source Code Cross Referenced for FilePermissionTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » io » 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.luni.tests.java.io 
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.luni.tests.java.io;
019:
020:        import java.io.File;
021:        import java.io.FilePermission;
022:        import java.security.PermissionCollection;
023:
024:        import junit.framework.TestCase;
025:
026:        public class FilePermissionTest extends TestCase {
027:
028:            FilePermission readAllFiles = new FilePermission("<<ALL FILES>>",
029:                    "read");
030:
031:            FilePermission alsoReadAllFiles = new FilePermission(
032:                    "<<ALL FILES>>", "read");
033:
034:            FilePermission allInCurrent = new FilePermission("*",
035:                    "read, write, execute,delete");
036:
037:            FilePermission readInCurrent = new FilePermission("*", "read");
038:
039:            FilePermission readInFile = new FilePermission("aFile.file", "read");
040:
041:            /**
042:             * @tests java.io.FilePermission#FilePermission(java.lang.String,
043:             *        java.lang.String)
044:             */
045:            public void test_ConstructorLjava_lang_StringLjava_lang_String() {
046:                assertTrue("Used to test", true);
047:                FilePermission constructFile = new FilePermission(
048:                        "test constructor", "write");
049:                assertEquals(
050:                        "action given to the constructor did not correspond - constructor failed",
051:                        "write", constructFile.getActions());
052:                assertTrue(
053:                        "name given to the constructor did not correspond - constructor failed",
054:                        constructFile.getName() == "test constructor");
055:
056:                // Regression test for HARMONY-1050
057:                try {
058:                    new FilePermission(null, "drink");
059:                    fail("Expected IAE");
060:                } catch (IllegalArgumentException e) {
061:                    // Expected
062:                }
063:
064:                try {
065:                    new FilePermission(null, "read");
066:                    fail("Expected NPE");
067:                } catch (NullPointerException e) {
068:                    // Expected
069:                }
070:
071:                try {
072:                    new FilePermission(null, null);
073:                    fail("Expected IAE");
074:                } catch (IllegalArgumentException e) {
075:                    // Expected
076:                }
077:            }
078:
079:            /**
080:             * @tests java.io.FilePermission#getActions()
081:             */
082:            public void test_getActions() {
083:                assertEquals("getActions should have returned only read",
084:                        "read", readAllFiles.getActions());
085:                assertEquals("getActions should have returned all actions",
086:                        "read,write,execute,delete", allInCurrent.getActions());
087:            }
088:
089:            /**
090:             * @tests java.io.FilePermission#equals(java.lang.Object)
091:             */
092:            public void test_equalsLjava_lang_Object() {
093:                assertTrue(
094:                        "returned false when two instance of FilePermission is equal",
095:                        readAllFiles.equals(alsoReadAllFiles));
096:                assertTrue(
097:                        "returned true when two instance	of FilePermission is not equal",
098:                        !(readInCurrent.equals(readInFile)));
099:            }
100:
101:            /**
102:             * @tests java.io.FilePermission#implies(java.security.Permission)
103:             */
104:            public void test_impliesLjava_security_Permission() {
105:                assertTrue("Returned true for non-subset of actions",
106:                        !readAllFiles.implies(allInCurrent));
107:                assertTrue("Returned true for non-subset of files",
108:                        !allInCurrent.implies(readAllFiles));
109:                assertTrue("Returned false for subset of actions", allInCurrent
110:                        .implies(readInCurrent));
111:                assertTrue("Returned false for subset of files", readAllFiles
112:                        .implies(readInCurrent));
113:                assertTrue("Returned false for subset of files and actions",
114:                        allInCurrent.implies(readInFile));
115:                assertTrue("Returned false for equal FilePermissions",
116:                        readAllFiles.implies(alsoReadAllFiles));
117:
118:                FilePermission fp3 = new FilePermission("/bob/*".replace('/',
119:                        File.separatorChar), "read,write");
120:                FilePermission fp4 = new FilePermission("/bob/".replace('/',
121:                        File.separatorChar), "write");
122:                assertTrue("returned true for same dir using * and not *", !fp3
123:                        .implies(fp4));
124:                FilePermission fp5 = new FilePermission("/bob/file".replace(
125:                        '/', File.separatorChar), "write");
126:                assertTrue("returned false for same dir using * and file", fp3
127:                        .implies(fp5));
128:
129:                FilePermission fp6 = new FilePermission("/bob/".replace('/',
130:                        File.separatorChar), "read,write");
131:                FilePermission fp7 = new FilePermission("/bob/*".replace('/',
132:                        File.separatorChar), "write");
133:                assertTrue("returned false for same dir using not * and *",
134:                        !fp6.implies(fp7));
135:                assertTrue("returned false for same subdir", fp6.implies(fp4));
136:
137:                FilePermission fp8 = new FilePermission("/".replace('/',
138:                        File.separatorChar), "read,write");
139:                FilePermission fp9 = new FilePermission("/".replace('/',
140:                        File.separatorChar), "write");
141:                assertTrue("returned false for same dir", fp8.implies(fp9));
142:
143:                FilePermission fp10 = new FilePermission("/".replace('/',
144:                        File.separatorChar), "read,write");
145:                FilePermission fp11 = new FilePermission("/".replace('/',
146:                        File.separatorChar), "write");
147:                assertTrue("returned false for same dir", fp10.implies(fp11));
148:
149:                FilePermission fp12 = new FilePermission("/*".replace('/',
150:                        File.separatorChar), "read,write");
151:                assertTrue("returned false for same dir using * and dir", !fp12
152:                        .implies(fp10));
153:
154:                // Regression for HARMONY-47
155:                char separator = File.separatorChar;
156:                char nonSeparator = (separator == '/') ? '\\' : '/';
157:
158:                FilePermission fp1 = new FilePermission(nonSeparator + "*",
159:                        "read");
160:                FilePermission fp2 = new FilePermission(separator + "a", "read");
161:                assertFalse("Assert 0: non-separator worked", fp1.implies(fp2));
162:                fp1 = new FilePermission(nonSeparator + "-", "read");
163:                assertFalse("Assert 1: non-separator worked", fp1.implies(fp2));
164:            }
165:
166:            /**
167:             * @tests java.io.FilePermission#newPermissionCollection()
168:             */
169:            public void test_newPermissionCollection() {
170:                char s = File.separatorChar;
171:                FilePermission perm[] = new FilePermission[4];
172:                perm[0] = readAllFiles;
173:                perm[1] = allInCurrent;
174:                perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
175:                        "read,write");
176:                perm[3] = new FilePermission(s + "tmp" + s + "test" + s
177:                        + "collection.file", "read");
178:
179:                PermissionCollection collect = perm[0]
180:                        .newPermissionCollection();
181:                for (int i = 0; i < perm.length; i++) {
182:                    collect.add(perm[i]);
183:                }
184:                assertTrue("returned false for subset of files", collect
185:                        .implies(new FilePermission("*", "write")));
186:                assertTrue("returned false for subset of name and action",
187:                        collect.implies(new FilePermission(s + "tmp", "read")));
188:                assertTrue("returned true for non subset of file and action",
189:                        collect.implies(readInFile));
190:
191:                FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
192:                        File.separatorChar), "read");
193:                PermissionCollection fpc = fp1.newPermissionCollection();
194:                fpc.add(fp1);
195:                fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
196:                        File.separatorChar), "write"));
197:                FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
198:                        .replace('/', File.separatorChar), "read,write");
199:                assertTrue("collection does not collate", fpc.implies(fp2));
200:            }
201:
202:            /**
203:             * @tests java.io.FilePermission#hashCode()
204:             */
205:            public void test_hashCode() {
206:                assertTrue(
207:                        "two equal filePermission instances returned different hashCode",
208:                        readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
209:                assertTrue(
210:                        "two filePermission instances with same permission name returned same hashCode",
211:                        readInCurrent.hashCode() != allInCurrent.hashCode());
212:
213:            }
214:        }
w__ww_._j_a___va__2__s___._co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.