1 /*******************************************************************************
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
10 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
20 ******************************************************************************/
21 package org.onap.aaf.cadi.util.test;
23 import static org.junit.Assert.*;
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;
33 import static org.hamcrest.CoreMatchers.*;
36 import org.onap.aaf.cadi.util.Chmod;
38 public class JU_Chmod {
41 private String filePath;
44 public void setup() throws IOException {
45 file = File.createTempFile("chmod_test", "");
46 filePath = file.getAbsolutePath();
50 public void tearDown() {
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"));
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--"));
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--------"));