Get proper message in test logger appender 90/79390/3
authorJim Hahn <jrh3@att.com>
Thu, 28 Feb 2019 18:00:16 +0000 (13:00 -0500)
committerJim Hahn <jrh3@att.com>
Thu, 28 Feb 2019 18:22:50 +0000 (13:22 -0500)
The logger appender that's used in junit tests was getting the
raw message, which still had "{}" place-holders in it.  Fixed that.

Split a test method to avoid checkstyle error.

Change-Id: I57571d8717aaee4adb7df186fe156501e9cc669e
Issue-ID: POLICY-1444
Signed-off-by: Jim Hahn <jrh3@att.com>
utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java

index 5ccb13e..19c5096 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START====================================================
  * Common Utils-Test
  * =============================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ public class ExtractAppender extends AppenderBase<ILoggingEvent> {
     @Override
     protected void append(final ILoggingEvent event) {
 
-        String msg = event.getMessage();
+        String msg = event.getFormattedMessage();
 
         synchronized (patterns) {
             if (patterns.isEmpty()) {
index eee60c3..e01ed41 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * Common Utils-Test
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * 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.
@@ -205,6 +205,15 @@ public class ExtractAppenderTest {
         assertEquals(strList("hello", "world"), appender.getExtracted());
     }
 
+    @Test
+    public void testAppendILoggingEvent_Formatted() {
+        ExtractAppender appender = makeAppender();
+
+        logger.info("hello {} world{}", "there", "!");
+
+        assertEquals(strList("hello there world!"), appender.getExtracted());
+    }
+
     @Test
     public void testAppendILoggingEvent_MatchFirstPattern() {
         ExtractAppender appender = makeAppender("abc[0-9]", "def[0-9]");
@@ -402,7 +411,7 @@ public class ExtractAppenderTest {
 
     /**
      * Adds multiple threads to perform some function repeatedly until the given time is reached.
-     * 
+     *
      * @param tend time, in milliseconds, when the test should terminate
      * @param haderr this will be set to {@code true} if the function throws an exception other than
      *        an InterruptedException
@@ -437,7 +446,7 @@ public class ExtractAppenderTest {
 
     /**
      * Makes an appender that recognizes the given set of strings.
-     * 
+     *
      * @param strings regular expressions to be matched
      * @return a new appender
      */
@@ -451,7 +460,7 @@ public class ExtractAppenderTest {
 
     /**
      * Adds an appender to the logger.
-     * 
+     *
      * @param app appender to be added
      */
     private void addAppender(ExtractAppender app) {
@@ -463,7 +472,7 @@ public class ExtractAppenderTest {
 
     /**
      * Converts an array of strings into a list of strings.
-     * 
+     *
      * @param strings array of strings
      * @return a list of the strings
      */