Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / util / test / JU_Chmod.java
1 /*******************************************************************************
2  * * org.onap.aaf
3  * * ===========================================================================
4  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5  * * ===========================================================================
6  * * Licensed under the Apache License, Version 2.0 (the "License");
7  * * you may not use this file except in compliance with the License.
8  * * 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, software
13  * * distributed under the License is distributed on an "AS IS" BASIS,
14  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * * See the License for the specific language governing permissions and
16  * * limitations under the License.
17  * * ============LICENSE_END====================================================
18  * *
19  * *
20  ******************************************************************************/
21 package org.onap.aaf.cadi.util.test;
22
23 import static org.junit.Assert.*;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.nio.file.attribute.PosixFilePermission;
30 import java.nio.file.attribute.PosixFilePermissions;
31 import java.util.Set;
32
33 import static org.hamcrest.CoreMatchers.*;
34 import org.junit.*;
35
36 import org.onap.aaf.cadi.util.Chmod;
37
38 public class JU_Chmod {
39
40     private File file;
41     private String filePath;
42
43     @Before
44     public void setup() throws IOException {
45         file = File.createTempFile("chmod_test", "");
46         filePath = file.getAbsolutePath();
47     }
48
49     @After
50     public void tearDown() {
51         file.delete();
52     }
53
54     @Test
55     public void to755Test() throws IOException {
56         Chmod.to755.chmod(file);
57         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
58         assertThat(PosixFilePermissions.toString(set), is("rwxr-xr-x"));
59     }
60
61     @Test
62     public void to644Test() throws IOException {
63         Chmod.to644.chmod(file);
64         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
65         assertThat(PosixFilePermissions.toString(set), is("rw-r--r--"));
66     }
67
68     @Test
69     public void to400Test() throws IOException {
70         Chmod.to400.chmod(file);
71         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
72         assertThat(PosixFilePermissions.toString(set), is("r--------"));
73     }
74
75 }