1 package org.onap.aai.sparky.logging.util;
3 import static org.junit.Assert.assertEquals;
6 import org.onap.aai.sparky.logging.AaiUiMsgs;
8 import com.att.eelf.i18n.EELFResourceManager;
10 public class LoggingMessageTemplateTest {
13 public void validateAllMessageEnumsHaveValidMessageFormats() {
16 * I discovered that some of the message formats had missing characters
17 * which made the EELFResourceManager interpret the message format as null
18 * which would inturn randomly geneate Null-Pointer-Exceptions while trying
19 * log formatted messages.
21 * Two concrete examples of this issue are as follows, from the AaiUiMsgs.properties
23 * ERROR_PROCESSING_REQUEST=\
25 * Failure to process request with error: {1}
27 * ERROR_PROCESSING_REQUEST=\
29 * Failure to process request with error: {1}
31 * Both of these formats look valid except for the second line. The code is expected to be terminated with a |\
32 * and this character sequence was missing from 4 of the message enums in our file. I created this
33 * test case to catch any future formatting errors of the message templates. There is no obvious error that
34 * exposes this problem until we experience an NPE at runtime, but even then it's not clear as to why it happened.
35 * Hopefully now we will be able to at least catch those issues before they happen.
39 int numMessageTemplatesWithMissingFormats = 0;
41 for ( AaiUiMsgs x : AaiUiMsgs.values() ) {
45 String format = EELFResourceManager.getMessage(x);
49 numMessageTemplatesWithMissingFormats++;
51 .println("Message enum = " + x + " has a missing message format.");
56 assertEquals(0, numMessageTemplatesWithMissingFormats);