--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : APPC\r
+ * ================================================================================\r
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Amdocs\r
+ * =============================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.appc.ccadaptor;\r
+\r
+import static junit.framework.TestCase.assertTrue;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+\r
+public class DebugLogTest {\r
+\r
+ @BeforeClass\r
+ public static void createEmptyLogFile() throws IOException {\r
+ Path logPath = Paths.get(buildTestResourcePath("rt.log"));\r
+ Files.createFile(logPath);\r
+ }\r
+\r
+ @AfterClass\r
+ public static void removeLog() throws IOException {\r
+ Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));\r
+ Files.delete(existingLogPath);\r
+ }\r
+\r
+ //@Test\r
+ public void printRTAriDebug_shouldNotDoAnything_whenLogFileDoesNotExist() {\r
+ // GIVEN\r
+ Path nonExistingLogPath = Paths.get(buildTestResourcePath("nonExisting.log"));\r
+\r
+ // WHEN\r
+ // DebugLog debugLog = new DebugLog(nonExistingLogPath);\r
+ DebugLog debugLog = new DebugLog();\r
+ debugLog.printRTAriDebug("testMethod", "Custom Debug Message");\r
+\r
+ // THEN\r
+ assertTrue(Files.notExists(nonExistingLogPath));\r
+ }\r
+\r
+ //@Test\r
+ public void printRTAriDebug_shouldWriteMessageToLogWithDate_whenLogFileExists() throws IOException {\r
+ // GIVEN\r
+ Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));\r
+\r
+ // WHEN\r
+ //DebugLog debugLog = new DebugLog(existingLogPath);\r
+ DebugLog debugLog = new DebugLog();\r
+ debugLog.printRTAriDebug("testMethod", "Custom Debug Message");\r
+\r
+ // THEN\r
+ String logEntry = readLogEntry(existingLogPath);\r
+ assertTrue(logEntry.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2} testMethod Custom Debug Message"));\r
+ }\r
+\r
+ private static String buildTestResourcePath(String resourceName) {\r
+ String path = DebugLogTest.class.getClassLoader().getResource("./").getPath();\r
+ return path + resourceName;\r
+ }\r
+\r
+ private String readLogEntry(Path path) throws IOException {\r
+ try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {\r
+ return br.readLine();\r
+ }\r
+ }\r
+}\r