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 ******************************************************************************/
22 package org.onap.aaf.cadi.util.test;
24 import static org.junit.Assert.*;
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;
34 import static org.hamcrest.CoreMatchers.*;
37 import org.onap.aaf.cadi.util.Chmod;
39 public class JU_Chmod {
42 private String filePath;
45 public void setup() throws IOException {
46 file = File.createTempFile("chmod_test", "");
47 filePath = file.getAbsolutePath();
51 public void tearDown() {
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"));
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--"));
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--------"));