From 0e2928da2b2404f40848640e5343708cabeab410 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 28 Feb 2019 13:00:16 -0500 Subject: 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 --- .../utils/test/log/logback/ExtractAppender.java | 4 ++-- .../test/log/logback/ExtractAppenderTest.java | 23 +++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'utils-test') 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 { @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. @@ -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 */ -- cgit 1.2.3-korg