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.FilenameFilter;
28 import java.io.IOException;
30 import org.junit.Before;
31 import org.junit.Test;
33 public class JU_LogFileNamerTest {
34 private File dir = new File(".");
37 public void setUp() throws Exception {
40 private void cleanup(String name) {
41 // System.out.println("XXXX" + dir.getAbsolutePath());
42 for(File f : dir.listFiles(new FilenameFilter() {
44 public boolean accept(File dir, String name) {
45 return name.contains(name) && name.endsWith(".log");
48 // System.out.println("Deleting " + f.getAbsolutePath());
55 public void test() throws IOException {
56 String name = "Append";
58 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
59 assertEquals(logFileNamer, logFileNamer.noPID());
61 logFileNamer.setAppender(name);
62 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
63 dir.getCanonicalFile() + File.separator + "log-" + name + ".log");
65 logFileNamer.setAppender(name);
66 assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
67 dir.getCanonicalFile() + File.separator + "log-" + name + ".0.log");
69 cleanup("log-" + name);
74 public void testBlankRoot() throws IOException {
75 String name = "Different";
77 LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
78 assertEquals(logFileNamer, logFileNamer.noPID());
80 logFileNamer.setAppender(name);
81 assertEquals(System.getProperty("LOG4J_FILENAME_Different"),
82 dir.getCanonicalPath() + File.separator + name + ".log");
84 logFileNamer.setAppender(name);
85 assertEquals(System.getProperty("LOG4J_FILENAME_Different"),
86 dir.getCanonicalPath() + File.separator + name + ".0.log");