2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.misc.env.log4j;
24 import static org.junit.Assert.assertEquals;
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;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
37 public class JU_LogFileNamerTest {
38 private File dir = new File(".");
40 private String ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
43 public void setUp() throws Exception {
47 public void test() throws IOException {
48 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
49 assertEquals(logFileNamer, logFileNamer.noPID());
51 logFileNamer.setAppender("Append");
52 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
53 dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_0.log");
55 logFileNamer.setAppender("Append");
56 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
57 dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_1.log");
61 public void testBlankRoot() throws IOException {
62 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
63 assertEquals(logFileNamer, logFileNamer.noPID());
65 logFileNamer.setAppender("Append");
66 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
67 dir.getCanonicalPath() + File.separator + "Append" + ending + "_0.log");
69 logFileNamer.setAppender("Append");
70 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
71 dir.getCanonicalPath() + File.separator + "Append" + ending + "_1.log");
75 public void tearDown() throws IOException {
76 File file = new File("./log-Append" + ending + "_0.log");
78 Files.delete(Paths.get(file.getAbsolutePath()));
80 file = new File("./log-Append" + ending + "_1.log");
82 Files.delete(Paths.get(file.getAbsolutePath()));
84 file = new File("./Append" + ending + "_0.log");
86 Files.delete(Paths.get(file.getAbsolutePath()));
88 file = new File("./Append" + ending + "_1.log");
90 Files.delete(Paths.get(file.getAbsolutePath()));