2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.sparky.logging.util;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Test;
27 import org.onap.aai.sparky.logging.AaiUiMsgs;
29 import com.att.eelf.i18n.EELFResourceManager;
31 public class LoggingMessageTemplateTest {
34 public void validateAllMessageEnumsHaveValidMessageFormats() {
37 * I discovered that some of the message formats had missing characters
38 * which made the EELFResourceManager interpret the message format as null
39 * which would inturn randomly geneate Null-Pointer-Exceptions while trying
40 * log formatted messages.
42 * Two concrete examples of this issue are as follows, from the AaiUiMsgs.properties
44 * ERROR_PROCESSING_REQUEST=\
46 * Failure to process request with error: {1}
48 * ERROR_PROCESSING_REQUEST=\
50 * Failure to process request with error: {1}
52 * Both of these formats look valid except for the second line. The code is expected to be terminated with a |\
53 * and this character sequence was missing from 4 of the message enums in our file. I created this
54 * test case to catch any future formatting errors of the message templates. There is no obvious error that
55 * exposes this problem until we experience an NPE at runtime, but even then it's not clear as to why it happened.
56 * Hopefully now we will be able to at least catch those issues before they happen.
60 int numMessageTemplatesWithMissingFormats = 0;
62 for ( AaiUiMsgs x : AaiUiMsgs.values() ) {
66 String format = EELFResourceManager.getMessage(x);
70 numMessageTemplatesWithMissingFormats++;
72 .println("Message enum = " + x + " has a missing message format.");
77 assertEquals(0, numMessageTemplatesWithMissingFormats);