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====================================================
21 package org.onap.aaf.misc.env.log4j;
23 import static org.junit.Assert.assertEquals;
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;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
36 public class JU_LogFileNamerTest {
37 private File dir = new File(".");
39 private String ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
42 public void setUp() throws Exception {
46 public void test() throws IOException {
47 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
48 assertEquals(logFileNamer, logFileNamer.noPID());
50 logFileNamer.setAppender("Append");
51 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
52 dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_0.log");
54 logFileNamer.setAppender("Append");
55 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
56 dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_1.log");
60 public void testBlankRoot() throws IOException {
61 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
62 assertEquals(logFileNamer, logFileNamer.noPID());
64 logFileNamer.setAppender("Append");
65 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
66 dir.getCanonicalPath() + File.separator + "Append" + ending + "_0.log");
68 logFileNamer.setAppender("Append");
69 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
70 dir.getCanonicalPath() + File.separator + "Append" + ending + "_1.log");
74 public void tearDown() throws IOException {
75 File file = new File("./log-Append" + ending + "_0.log");
77 Files.delete(Paths.get(file.getAbsolutePath()));
79 file = new File("./log-Append" + ending + "_1.log");
81 Files.delete(Paths.get(file.getAbsolutePath()));
83 file = new File("./Append" + ending + "_0.log");
85 Files.delete(Paths.get(file.getAbsolutePath()));
87 file = new File("./Append" + ending + "_1.log");
89 Files.delete(Paths.get(file.getAbsolutePath()));