aboutsummaryrefslogtreecommitdiffstats
path: root/utils-test/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-02-28 13:00:16 -0500
committerJim Hahn <jrh3@att.com>2019-02-28 13:22:50 -0500
commit0e2928da2b2404f40848640e5343708cabeab410 (patch)
treef9d445edd47819de4ca543d51217e15296d379fb /utils-test/src
parent3849ce18d51e308bbd58b71219472c23b5f3e814 (diff)
Get proper message in test logger appender
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>
Diffstat (limited to 'utils-test/src')
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java4
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java23
2 files changed, 18 insertions, 9 deletions
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
index 5ccb13ee..19c50968 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
@@ -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()) {
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
index eee60c38..e01ed417 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
@@ -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.
@@ -206,6 +206,15 @@ public class ExtractAppenderTest {
}
@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
*/