e75b8ef8d19bb6586a671281156e307fc5ef8d5f
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / logging / util / LoggingMessageTemplateTest.java
1 package org.onap.aai.sparky.logging.util;
2
3 import static org.junit.Assert.assertEquals;
4
5 import org.junit.Test;
6 import org.onap.aai.sparky.logging.AaiUiMsgs;
7
8 import com.att.eelf.i18n.EELFResourceManager;
9
10 public class LoggingMessageTemplateTest {
11   
12   @Test 
13   public void validateAllMessageEnumsHaveValidMessageFormats() {
14     
15     /*
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.
20      * 
21      * Two concrete examples of this issue are as follows, from the AaiUiMsgs.properties
22      * 
23      * ERROR_PROCESSING_REQUEST=\
24      *      AAIUI30037E
25      *      Failure to process request with error: {1}
26      *
27      * ERROR_PROCESSING_REQUEST=\
28      *     AAIUI30037E\
29      *     Failure to process request with error: {1}
30      *    
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.   
36      */
37     
38       
39     int numMessageTemplatesWithMissingFormats = 0;
40     
41     for ( AaiUiMsgs x : AaiUiMsgs.values() ) {
42       
43       if (x != null) {
44
45         String format = EELFResourceManager.getMessage(x);
46
47         if (format == null) {
48           
49           numMessageTemplatesWithMissingFormats++;
50           System.out
51               .println("Message enum = " + x + " has a missing message format.");
52         }
53       }
54     }
55       
56     assertEquals(0, numMessageTemplatesWithMissingFormats);
57       
58   }
59   
60  
61
62 }