View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.codehaus.plexus.archiver.util;
20  
21  import org.codehaus.plexus.logging.Logger;
22  import org.codehaus.plexus.logging.console.ConsoleLogger;
23  import junit.framework.TestCase;
24  
25  /**
26   * @author Olivier Lamy
27   */
28  public class FilePermissionUtilsTest
29      extends TestCase
30  {
31  
32      Logger getLogger()
33      {
34          return new ConsoleLogger( Logger.LEVEL_DEBUG, "foo" );
35  
36      }
37  
38      public void testOnlyWritableOnlyUser() throws Exception
39      {
40          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode( "200", getLogger() );
41          assertTrue( fp.isWritable() );
42          assertTrue( fp.isOwnerOnlyWritable() );
43          assertFalse( fp.isExecutable() );
44          assertTrue( fp.isOwnerOnlyExecutable() );
45          assertFalse( fp.isReadable() );
46      }
47  
48      public void testExecAndRead()
49      {
50          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode( "500", getLogger() );
51          assertFalse( fp.isWritable() );
52          assertTrue( fp.isOwnerOnlyWritable() );
53          assertTrue( fp.isExecutable() );
54          assertTrue( fp.isOwnerOnlyExecutable() );
55          assertTrue( fp.isReadable() );
56      }
57  
58      public void testAllUser()
59      {
60          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode( "700", getLogger() );
61          assertTrue( fp.isWritable() );
62          assertTrue( fp.isOwnerOnlyWritable() );
63          assertTrue( fp.isExecutable() );
64          assertTrue( fp.isOwnerOnlyExecutable() );
65          assertTrue( fp.isReadable() );
66      }
67  
68      public void testAllAllUser()
69      {
70          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode( "707", getLogger() );
71          assertTrue( fp.isWritable() );
72          assertFalse( fp.isOwnerOnlyWritable() );
73          assertTrue( fp.isExecutable() );
74          assertFalse( fp.isOwnerOnlyExecutable() );
75          assertTrue( fp.isReadable() );
76          assertFalse( fp.isOwnerOnlyReadable() );
77      }
78  
79  }