Home | History | Annotate | Download | only in attribute
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package libcore.java.nio.file.attribute;
     18 
     19 import org.junit.Test;
     20 import static org.junit.Assert.assertEquals;
     21 import static junit.framework.TestCase.assertTrue;
     22 
     23 import java.nio.file.attribute.AclEntry;
     24 import java.nio.file.attribute.UserPrincipal;
     25 import java.nio.file.attribute.AclEntryType;
     26 import java.nio.file.attribute.AclEntryPermission;
     27 import java.nio.file.attribute.AclEntryFlag;
     28 import java.nio.file.Files;
     29 import java.nio.file.Paths;
     30 
     31 import java.util.Set;
     32 
     33 
     34 public class AclEntryTest {
     35 
     36     @Test
     37     public void testGetters() throws Exception {
     38         UserPrincipal user = Files.getOwner(Paths.get("."));
     39 
     40         AclEntry aclEntry = AclEntry.newBuilder()
     41             .setType(AclEntryType.ALLOW)
     42             .setPrincipal(user)
     43             .setFlags(AclEntryFlag.INHERIT_ONLY)
     44             .setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES)
     45             .build();
     46         assertEquals(AclEntryType.ALLOW, aclEntry.type());
     47         assertEquals(user, aclEntry.principal());
     48 
     49         Set<AclEntryPermission> permissions = aclEntry.permissions();
     50         assertEquals(2, permissions.size());
     51         assertTrue(permissions.contains(AclEntryPermission.READ_DATA));
     52         assertTrue(permissions.contains(AclEntryPermission.READ_ATTRIBUTES));
     53 
     54         Set<AclEntryFlag> flags = aclEntry.flags();
     55         assertEquals(1, flags.size());
     56         assertTrue(flags.contains(AclEntryFlag.INHERIT_ONLY));
     57     }
     58 }
     59