Remove Tabs, per Jococo
[aaf/authz.git] / misc / log4j / src / test / java / org / onap / aaf / misc / env / log4j / JU_LogFileNamerTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.misc.env.log4j;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.File;
27 import java.io.FilenameFilter;
28 import java.io.IOException;
29
30 import org.junit.Before;
31 import org.junit.Test;
32
33 public class JU_LogFileNamerTest {
34     private File dir = new File(".");
35
36     @Before
37     public void setUp() throws Exception {
38     }
39
40     private void cleanup(String name) {
41 //        System.out.println("XXXX" + dir.getAbsolutePath());
42         for(File f : dir.listFiles(new FilenameFilter() {
43             @Override
44             public boolean accept(File dir, String name) {
45                 return name.contains(name) && name.endsWith(".log");
46             }
47         })) {
48 //            System.out.println("Deleting " + f.getAbsolutePath());
49             f.delete();
50         };
51     }
52
53
54     @Test
55     public void test() throws IOException {
56         String name = "Append";
57         try {
58             LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
59             assertEquals(logFileNamer, logFileNamer.noPID());
60     
61             logFileNamer.setAppender(name);
62             assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
63                 dir.getCanonicalFile() + File.separator + "log-" + name + ".log");
64     
65             logFileNamer.setAppender(name);
66             assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
67                 dir.getCanonicalFile() + File.separator + "log-" + name + ".0.log");
68         } finally {
69             cleanup("log-" + name);
70         }
71     }
72
73     @Test
74     public void testBlankRoot() throws IOException {
75         String name = "Different";
76         try {
77             LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
78             assertEquals(logFileNamer, logFileNamer.noPID());
79     
80             logFileNamer.setAppender(name);
81             assertEquals(System.getProperty("LOG4J_FILENAME_Different"),
82                 dir.getCanonicalPath() + File.separator + name + ".log");
83     
84             logFileNamer.setAppender(name);
85             assertEquals(System.getProperty("LOG4J_FILENAME_Different"),
86                 dir.getCanonicalPath() + File.separator + name + ".0.log");
87         } finally {
88             cleanup(name);
89         }
90     }
91
92 }