2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Copyright (C) 2017 Amdocs
\r
8 * =============================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
21 * ============LICENSE_END=========================================================
\r
24 package org.onap.appc.ccadaptor;
\r
26 import static junit.framework.TestCase.assertTrue;
\r
28 import java.io.BufferedReader;
\r
29 import java.io.FileReader;
\r
30 import java.io.IOException;
\r
31 import java.nio.file.Files;
\r
32 import java.nio.file.Path;
\r
33 import java.nio.file.Paths;
\r
34 import org.junit.AfterClass;
\r
35 import org.junit.BeforeClass;
\r
36 import org.junit.Test;
\r
38 public class DebugLogTest {
\r
41 public static void createEmptyLogFile() throws IOException {
\r
42 Path logPath = Paths.get(buildTestResourcePath("rt.log"));
\r
43 Files.createFile(logPath);
\r
47 public static void removeLog() throws IOException {
\r
48 Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));
\r
49 Files.delete(existingLogPath);
\r
53 public void printRTAriDebug_shouldNotDoAnything_whenLogFileDoesNotExist() {
\r
55 Path nonExistingLogPath = Paths.get(buildTestResourcePath("nonExisting.log"));
\r
58 // DebugLog debugLog = new DebugLog(nonExistingLogPath);
\r
59 DebugLog debugLog = new DebugLog();
\r
60 debugLog.printRTAriDebug("testMethod", "Custom Debug Message");
\r
63 assertTrue(Files.notExists(nonExistingLogPath));
\r
67 public void printRTAriDebug_shouldWriteMessageToLogWithDate_whenLogFileExists() throws IOException {
\r
69 Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));
\r
72 //DebugLog debugLog = new DebugLog(existingLogPath);
\r
73 DebugLog debugLog = new DebugLog();
\r
74 debugLog.printRTAriDebug("testMethod", "Custom Debug Message");
\r
77 String logEntry = readLogEntry(existingLogPath);
\r
78 assertTrue(logEntry.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2} testMethod Custom Debug Message"));
\r
81 private static String buildTestResourcePath(String resourceName) {
\r
82 String path = DebugLogTest.class.getClassLoader().getResource("./").getPath();
\r
83 return path + resourceName;
\r
86 private String readLogEntry(Path path) throws IOException {
\r
87 try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
\r
88 return br.readLine();
\r