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