summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-adaptor/provider/src/test
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2018-01-11 11:04:11 +0100
committerPatrick Brady <pb071s@att.com>2018-01-25 18:32:18 +0000
commit331a0c05382516535755f179a29ced7a4924139d (patch)
tree2428d3947fcd32a7aebe445e33e7e7538911e00c /appc-config/appc-config-adaptor/provider/src/test
parentbe7e8515790ab3551e1cb339027f1346bab1e25a (diff)
Fix sonar issues and restore java style format
Reformat code according to Java Code Guidelines. Refactor of DebugLog test + new JUnits Change-Id: I4f8f03d133180f9315ab596e1093f44582d08068 Issue-ID: APPC-417 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'appc-config/appc-config-adaptor/provider/src/test')
-rw-r--r--appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/DebugLogTest.java114
1 files changed, 83 insertions, 31 deletions
diff --git a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/DebugLogTest.java b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/DebugLogTest.java
index 6fcb62675..472bdc70d 100644
--- a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/DebugLogTest.java
+++ b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/DebugLogTest.java
@@ -1,38 +1,90 @@
-/*-
+/*-
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.ccadaptor;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class DebugLogTest {
-
- @Test
- public void TestGetDateTime() {
- String DateTime = DebugLog.getDateTime();
- Assert.assertNotNull(DateTime);
- }
-
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.ccadaptor;
+
+import static junit.framework.TestCase.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class DebugLogTest {
+
+ @BeforeClass
+ public static void createEmptyLogFile() throws IOException {
+ Path logPath = Paths.get(buildTestResourcePath("rt.log"));
+ Files.createFile(logPath);
+ }
+
+ @AfterClass
+ public static void removeLog() throws IOException {
+ Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));
+ Files.delete(existingLogPath);
+ }
+
+ @Test
+ public void printRTAriDebug_shouldNotDoAnything_whenLogFileDoesNotExist() {
+ // GIVEN
+ Path nonExistingLogPath = Paths.get(buildTestResourcePath("nonExisting.log"));
+
+ // WHEN
+ DebugLog debugLog = new DebugLog(nonExistingLogPath);
+ debugLog.printRTAriDebug("testMethod", "Custom Debug Message");
+
+ // THEN
+ assertTrue(Files.notExists(nonExistingLogPath));
+ }
+
+ @Test
+ public void printRTAriDebug_shouldWriteMessageToLogWithDate_whenLogFileExists() throws IOException {
+ // GIVEN
+ Path existingLogPath = Paths.get(buildTestResourcePath("rt.log"));
+
+ // WHEN
+ DebugLog debugLog = new DebugLog(existingLogPath);
+ debugLog.printRTAriDebug("testMethod", "Custom Debug Message");
+
+ // THEN
+ String logEntry = readLogEntry(existingLogPath);
+ assertTrue(logEntry.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2} testMethod Custom Debug Message"));
+ }
+
+ private static String buildTestResourcePath(String resourceName) {
+ String path = DebugLogTest.class.getClassLoader().getResource("./").getPath();
+ return path + resourceName;
+ }
+
+ private String readLogEntry(Path path) throws IOException {
+ try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
+ return br.readLine();
+ }
+ }
} \ No newline at end of file