Mass removal of all Tabs (Style Warnings)
[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 package org.onap.aaf.misc.env.log4j;
22
23 import static org.junit.Assert.assertEquals;
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.text.SimpleDateFormat;
30 import java.util.Date;
31
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35
36 public class JU_LogFileNamerTest {
37     private File dir = new File(".");
38
39     private String ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
40
41     @Before
42     public void setUp() throws Exception {
43     }
44
45     @Test
46     public void test() throws IOException {
47         LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
48         assertEquals(logFileNamer, logFileNamer.noPID());
49
50         logFileNamer.setAppender("Append");
51         assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
52             dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_0.log");
53
54         logFileNamer.setAppender("Append");
55         assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
56             dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_1.log");
57     }
58
59     @Test
60     public void testBlankRoot() throws IOException {
61         LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
62         assertEquals(logFileNamer, logFileNamer.noPID());
63
64         logFileNamer.setAppender("Append");
65         assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
66             dir.getCanonicalPath() + File.separator + "Append" + ending + "_0.log");
67
68         logFileNamer.setAppender("Append");
69         assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
70             dir.getCanonicalPath() + File.separator + "Append" + ending + "_1.log");
71     }
72
73     @After
74     public void tearDown() throws IOException {
75         File file = new File("./log-Append" + ending + "_0.log");
76         if (file.exists()) {
77             Files.delete(Paths.get(file.getAbsolutePath()));
78         }
79         file = new File("./log-Append" + ending + "_1.log");
80         if (file.exists()) {
81             Files.delete(Paths.get(file.getAbsolutePath()));
82         }
83         file = new File("./Append" + ending + "_0.log");
84         if (file.exists()) {
85             Files.delete(Paths.get(file.getAbsolutePath()));
86         }
87         file = new File("./Append" + ending + "_1.log");
88         if (file.exists()) {
89             Files.delete(Paths.get(file.getAbsolutePath()));
90         }
91     }
92
93 }