Sonar Fixes, Formatting
[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
22 package org.onap.aaf.cadi.util.test;
23
24 import static org.junit.Assert.*;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.nio.file.attribute.PosixFilePermission;
31 import java.nio.file.attribute.PosixFilePermissions;
32 import java.util.Set;
33
34 import static org.hamcrest.CoreMatchers.*;
35 import org.junit.*;
36
37 import org.onap.aaf.cadi.util.Chmod;
38
39 public class JU_Chmod {
40
41     private File file;
42     private String filePath;
43
44     @Before
45     public void setup() throws IOException {
46         file = File.createTempFile("chmod_test", "");
47         filePath = file.getAbsolutePath();
48     }
49
50     @After
51     public void tearDown() {
52         file.delete();
53     }
54
55     @Test
56     public void to755Test() throws IOException {
57         Chmod.to755.chmod(file);
58         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
59         assertThat(PosixFilePermissions.toString(set), is("rwxr-xr-x"));
60     }
61
62     @Test
63     public void to644Test() throws IOException {
64         Chmod.to644.chmod(file);
65         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
66         assertThat(PosixFilePermissions.toString(set), is("rw-r--r--"));
67     }
68
69     @Test
70     public void to400Test() throws IOException {
71         Chmod.to400.chmod(file);
72         Set<PosixFilePermission> set = Files.getPosixFilePermissions(Paths.get(filePath));
73         assertThat(PosixFilePermissions.toString(set), is("r--------"));
74     }
75
76 }