Adjust sparky parent pom
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / logging / util / LoggingMessageTemplateTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.sparky.logging.util;
23
24 import static org.junit.Assert.assertEquals;
25
26 import org.junit.Test;
27 import org.onap.aai.sparky.logging.AaiUiMsgs;
28
29 import com.att.eelf.i18n.EELFResourceManager;
30
31 public class LoggingMessageTemplateTest {
32   
33   @Test 
34   public void validateAllMessageEnumsHaveValidMessageFormats() {
35     
36     /*
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.
41      * 
42      * Two concrete examples of this issue are as follows, from the AaiUiMsgs.properties
43      * 
44      * ERROR_PROCESSING_REQUEST=\
45      *      AAIUI30037E
46      *      Failure to process request with error: {1}
47      *
48      * ERROR_PROCESSING_REQUEST=\
49      *     AAIUI30037E\
50      *     Failure to process request with error: {1}
51      *    
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.   
57      */
58     
59       
60     int numMessageTemplatesWithMissingFormats = 0;
61     
62     for ( AaiUiMsgs x : AaiUiMsgs.values() ) {
63       
64       if (x != null) {
65
66         String format = EELFResourceManager.getMessage(x);
67
68         if (format == null) {
69           
70           numMessageTemplatesWithMissingFormats++;
71           System.out
72               .println("Message enum = " + x + " has a missing message format.");
73         }
74       }
75     }
76       
77     assertEquals(0, numMessageTemplatesWithMissingFormats);
78       
79   }
80   
81  
82
83 }