aboutsummaryrefslogtreecommitdiffstats
path: root/eelf-logging/src/test/java/org/onap/aai/cl/eelf/AAILoggerAdapterTest.java
blob: 1afe9ed17f02219aba71db90f3d84acdadf932bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
/*-
 * ============LICENSE_START=======================================================
 * Common Logging Library
 * ================================================================================
 * Copyright (C) 2017 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.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.aai.cl.eelf;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.i18n.EELFResolvableResourceEnum;

import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.cl.api.LogFields;
import org.onap.aai.cl.api.LogLine;
import org.onap.aai.cl.api.LogLine.DefinedFields;
import org.onap.aai.cl.api.LogLine.LogLineType;
import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.cl.mdc.MdcOverride;
import org.slf4j.Marker;

/** This suite of tests is intended to validate the functionality of our wrapper
 * around the {@link EELFLogger}. */
public class AAILoggerAdapterTest {

    private enum InvalidLogCodeEnum {
        BAD_LOGCODE1
    }

    private static final String LOGGER_NAME = "UnitTestLogAdapter";
    private static final String METRICS_LOGGER_NAME = "UnitTestMetricsLogAdapter";
    private static final String AUDIT_LOGGER_NAME = "UnitTestAuditLogAdapter";
    private static final String FIRST_ARG = "First Arg";
    private static final String SECOND_ARG = "Second Arg";

    private TestLogger logger;
    private AaiLoggerAdapter loggerAdapter;
    private AaiLoggerAdapter metricsLoggerAdapter;
    private AaiLoggerAdapter auditLoggerAdapter;

    /**
     * Setup before running tests.
     */
    @Before
    public void setup() {
        logger = new TestLogger();
        loggerAdapter = new AaiLoggerAdapter(logger, LogLineType.ERROR, LOGGER_NAME);
        metricsLoggerAdapter = new AaiLoggerAdapter(logger, LogLineType.METRICS, METRICS_LOGGER_NAME);
        auditLoggerAdapter = new AaiLoggerAdapter(logger, LogLineType.AUDIT, AUDIT_LOGGER_NAME);
    }

    /** This test validates the the {@link AaiLoggerAdapter} is able to deal with
     * log code enums which do not extend the {@link EELFResolvableEnum}
     * placeholder (meaning that the EELF framework would not know how to parse
     * them). */
    @Test
    public void badLogCodeEnumTest() {

        // For each supported log level, validate that if a log code is
        // specified which does not extend EELFResolvableEnum, then a
        // generic 'unparsable log code' statement is generated instead
        // of a correctly parsed log statement.

        loggerAdapter.info(InvalidLogCodeEnum.BAD_LOGCODE1, "arg1");
        assertBadLogCodeMessage(logger.getMessage(), InvalidLogCodeEnum.BAD_LOGCODE1);

        loggerAdapter.debug(InvalidLogCodeEnum.BAD_LOGCODE1, "arg1", "arg2");
        assertBadLogCodeMessage(logger.getMessage(), InvalidLogCodeEnum.BAD_LOGCODE1);

        loggerAdapter.warn(InvalidLogCodeEnum.BAD_LOGCODE1, "arg1", "arg2");
        assertBadLogCodeMessage(logger.getMessage(), InvalidLogCodeEnum.BAD_LOGCODE1);

        loggerAdapter.error(InvalidLogCodeEnum.BAD_LOGCODE1, "arg1", "arg2", "arg3");
        assertBadLogCodeMessage(logger.getMessage(), InvalidLogCodeEnum.BAD_LOGCODE1);

        loggerAdapter.error(InvalidLogCodeEnum.BAD_LOGCODE1, new LogFields(),
            new Throwable("Some exception"), "arg1");
        assertBadLogCodeMessage(logger.getMessage(), InvalidLogCodeEnum.BAD_LOGCODE1);
    }

    /** This test validates that INFO level logs are correctly parsed from the
     * resource bundle. */
    @Test
    public void logStatementInfoParsingTest() {

        // Generate a simple INFO log.
        loggerAdapter.info(UnitTestMsgs.SIMPLE_INFO_LOG, null);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg("UT0001I This is a simple info log with no arguments.");

        // Generate an INFO log with arguments.
        LogFields fields = new LogFields().setField(LogLine.DefinedFields.TARGET_SVC_NAME, "test");
        loggerAdapter.info(UnitTestMsgs.INFO_LOG_WITH_ARGS, fields, FIRST_ARG, SECOND_ARG);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(
            "UT0002I This is an info log with some arguments " + FIRST_ARG + " and " + SECOND_ARG);

        // Validate that log fields are being correctly populated.
        logger.validateLogFields(LogLineType.ERROR, fields);
    }

    /** Validate metrics log. */
    @Test
    public void logStatementMetricsTest() {
        // Generate an INFO log with arguments.
        MdcContext.initialize("xx-yy-zz", "MyService", "MyInstance", "MyPartner", "12.0.0.2");
        metricsLoggerAdapter.info(UnitTestMsgs.INFO_LOG_WITH_ARGS,
            new LogFields().setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, "Accepted")
                .setField(LogLine.DefinedFields.RESPONSE_CODE, 202),
            "arg1", "arg2");

        // Validate that the log code is correctly encoded in the log statement
        // and that the message was parsed from the bundle resource.
        logger.validateMetricsMsg("UT0002I This is an info log with some arguments arg1 and arg2");
        logger.validateMetricsRespStatus("202", "Accepted");

        // Validate MDC override
        MdcOverride override = new MdcOverride();
        override.addAttribute(MdcContext.MDC_REQUEST_ID, "New-requestID");

        LogFields fields = new LogFields()
            .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, "Accepted")
            .setField(LogLine.DefinedFields.RESPONSE_CODE, 202);

        metricsLoggerAdapter.info(UnitTestMsgs.INFO_LOG_WITH_ARGS, fields, override, "arg1", "arg2");
        logger.validateMetricsRequestId("New-requestID");

        // Validate that log fields are being correctly populated.
        logger.validateLogFields(LogLineType.METRICS, fields);
    }

    /** Validate metrics log. */
    @Test
    public void logStatementAuditTest() {
        // Generate an INFO log with arguments.
        MdcContext.initialize("xx-yy-aa", "MyService", "MyInstance", "MyPartner", "12.0.0.8");
        LogFields fields = new LogFields()
            .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, "Accepted")
            .setField(LogLine.DefinedFields.RESPONSE_CODE, 202);
        auditLoggerAdapter.info(UnitTestMsgs.INFO_LOG_WITH_ARGS, fields, "arg1", "arg2");

        // Validate that the log code is correctly encoded in the log statement
        // and that the message was parsed from the bundle resource.
        logger.validateAuditMsg("UT0002I This is an info log with some arguments arg1 and arg2");
        logger.validateAuditRespStatus("202", "Accepted");

        // Validate that log fields are being correctly populated.
        logger.validateLogFields(LogLineType.AUDIT, fields);
    }

    /** This test validates that ERROR level logs are correctly parsed from the
     * resource bundle. */
    @Test
    public void logStatementErrorParsingTest() {

        // Generate a simple ERROR log.
        loggerAdapter.error(UnitTestMsgs.SIMPLE_ERROR_LOG, null);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg("UT0001E This is a simple error log with no arguments.");

        // Generate an ERROR log with arguments.
        loggerAdapter.error(UnitTestMsgs.ERROR_LOG_WITH_ARGS, new LogFields(), FIRST_ARG, SECOND_ARG);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(
            "UT0002E This is an error log with some arguments " + FIRST_ARG + " and " + SECOND_ARG);
    }

    /** This test validates that WARNING level logs are correctly parsed from the
     * resource bundle. */
    @Test
    public void logStatementWarnParsingTest() {

        // Generate a simple ERROR log.
        loggerAdapter.warn(UnitTestMsgs.SIMPLE_WARN_LOG, null);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg("UT0001W This is a simple warning log with no arguments.");

        // Generate a WARNING log with arguments.
        loggerAdapter.warn(UnitTestMsgs.WARN_LOG_WITH_ARGS, FIRST_ARG, SECOND_ARG);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(
            "UT0002W This is a warning log with some arguments " + FIRST_ARG + " and " + SECOND_ARG);
    }

    /** This test validates that DEBUG level logs are correctly parsed from the
     * resource bundle. */
    @Test
    public void logStatementDebugParsingTest() {

        String simpleDebugMsg = "My simple debug message";

        // Generate a simple DEBUG log with no error code.
        loggerAdapter.debug(simpleDebugMsg);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(simpleDebugMsg);

        // Generate an ERROR log with arguments.
        loggerAdapter.debug(UnitTestMsgs.DEBUG_LOG_WITH_ARGS, FIRST_ARG, SECOND_ARG);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(
            "UT0001D This is a debug log with some arguments " + FIRST_ARG + " and " + SECOND_ARG);
    }

    /** This test validates that TRACE level logs are correctly parsed from the
     * resource bundle. */
    @Test
    public void logStatementTraceParsingTest() {

        // Generate a simple TRACE log with no error code.
        loggerAdapter.trace(UnitTestMsgs.SIMPLE_TRACE_LOG, null);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg("UT0001T This is a simple trace log with no arguments.");
        logger.validateLogLevel(EELFLogger.Level.TRACE);

        // Generate an ERROR log with arguments.
        loggerAdapter.trace(UnitTestMsgs.TRACE_LOG_WITH_ARGS, FIRST_ARG, SECOND_ARG);

        // Validate that the message was parsed from the bundle resource.
        logger.validateLogMsg(
            "UT0002T This is a trace log with some arguments " + FIRST_ARG + " and " + SECOND_ARG);
        logger.validateLogLevel(EELFLogger.Level.TRACE);
    }

    /** This is a convenience method that validates that a generated log message
     * contains the expected values when a log code could not be parsed.
     *
     * @param aLogMessage
     *          - The log message to be validated.
     * @param aLogCode
     *          - The error code that was passed to the logger. */
    private void assertBadLogCodeMessage(String aLogMessage, Enum aLogCode) {

        assertTrue("Expected 'unparseable log code' generic error string",
            logger.getMessage().contains(AaiLoggerAdapter.BAD_ENUM_MSG));
        assertTrue("Expected error string to include log code",
            logger.getMessage().contains(aLogCode.toString()));
    }

    /** This test validates the formatMsg method returns a properly formatted
     * message. */
    @Test
    public void formatMsgTest() {

        String expected1 = "UT0001I This is a simple info log with no arguments.";
        String expected2 = "UT0002I This is an info log with some arguments " + FIRST_ARG + " and " + SECOND_ARG;

        String message1 = loggerAdapter.formatMsg(UnitTestMsgs.SIMPLE_INFO_LOG);
        assertEquals("Invalid formatted msg1", message1, expected1);

        String message2 = loggerAdapter.formatMsg(UnitTestMsgs.INFO_LOG_WITH_ARGS, FIRST_ARG,
            SECOND_ARG);
        assertEquals("Invalid formatted msg2", message2, expected2);
    }

    /** This is an implementation of the {@link EELFLogger} which just caches the
     * last log statement passed to it and provides some convenience methods for
     * validating the contents of the log message.
     * <p>
     * The instance of the {@link AaiLoggerAdapter} that we are testing against
     * will use this implementation instead of a real {@link EELFLogger}. */
    private class TestLogger implements EELFLogger {

        // Some indices to use for extracting specific fields from the
        // log statement.
        private static final int MESSAGE_INDEX = 1;

        private static final int METRICE_TRANS_ID_INDEX = 2;
        private static final int METRICS_RESP_CODE_INDEX = 11;
        private static final int METRICS_RESP_STRING_INDEX = 12;
        private static final int METRICS_MSG_INDEX = 28;

        private static final int AUDIT_RESP_CODE_INDEX = 9;
        private static final int AUDIT_RESP_STRING_INDEX = 10;
        private static final int AUDIT_MSG_INDEX = 25;

        /** Stores the last log statement passed to the logger. */
        private String logMessage;

        private EELFLogger.Level logLevel;

        @Override
        public void warn(String msg) {
            logMessage = msg;
            logLevel = EELFLogger.Level.WARN;
        }

        @Override
        public void warn(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void warn(String msg, Throwable th) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void debug(String msg) {
            logMessage = msg;
            logLevel = EELFLogger.Level.DEBUG;
        }

        @Override
        public void debug(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void debug(String msg, Throwable th) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void trace(String msg) {
            logMessage = msg;
            logLevel = EELFLogger.Level.TRACE;
        }

        @Override
        public void trace(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void trace(String msg, Throwable th) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void info(String msg) {
            logMessage = msg;
            logLevel = EELFLogger.Level.INFO;
        }

        @Override
        public void info(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void error(String msg) {
            logMessage = msg;
            logLevel = EELFLogger.Level.ERROR;
        }

        @Override
        public void error(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void error(String msg, Throwable th) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public boolean isTraceEnabled() {
            return false;
        }

        @Override
        public boolean isInfoEnabled() {
            return false;
        }

        @Override
        public boolean isErrorEnabled() {
            return false;
        }

        @Override
        public boolean isWarnEnabled() {
            return false;
        }

        @Override
        public boolean isDebugEnabled() {
            return false;
        }

        @Override
        public void log(Level level, String msg, Throwable th, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void auditEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void auditEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void metricsEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void metricsEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void securityEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void securityEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void performanceEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void performanceEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void applicationEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void applicationEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void serverEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void serverEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void policyEvent(String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void policyEvent(Level level, String msg, Object... arguments) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }


        @Override
        public void setLevel(Level level) {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        @Override
        public void disableLogging() {
            throw new UnsupportedOperationException(
                "AAILoggerAdapter is not expected to call into this method.");
        }

        /** Convenience method to retrieve the log string that was produced by the
         * logger.
         *
         * @return - A log string. */
        public String getMessage() {
            return logMessage;
        }

        /** Validates that the parsed log message encoded in the last produced log
         * message matches the supplied expected value.
         *
         * @param aMessage
         *          - The expected log message. */
        public void validateLogMsg(String aMessage) {

            // Tokenize the log string.
            String[] tokens = tokenizeLogString();

            // Verify the log message.
            assertTrue("Unexpected log message in log string", aMessage.equals(tokens[MESSAGE_INDEX]));
        }

        public void validateLogFields(LogLineType logType, LogFields fields) {

            // Tokenize the log string.
            String[] tokens = tokenizeLogString();

            switch (logType) {

                case ERROR:
                    break;

                case METRICS:
                    if (fields.getField(DefinedFields.TARGET_SVC_NAME) != null) {
                        assertTrue(fields.getField(DefinedFields.TARGET_SVC_NAME).equals(tokens[9]));
                    }
                    if (fields.getField(DefinedFields.STATUS_CODE) != null) {
                        assertTrue(fields.getField(DefinedFields.STATUS_CODE).equals(tokens[10]));
                    }
                    if (fields.getField(DefinedFields.RESPONSE_CODE) != null) {
                        assertTrue(fields.getField(DefinedFields.RESPONSE_CODE).equals(tokens[11]));
                    }
                    if (fields.getField(DefinedFields.RESPONSE_DESCRIPTION) != null) {
                        assertTrue(fields.getField(DefinedFields.RESPONSE_DESCRIPTION).equals(tokens[12]));
                    }
                    if (fields.getField(DefinedFields.INSTANCE_UUID) != null) {
                        assertTrue(fields.getField(DefinedFields.INSTANCE_UUID).equals(tokens[13]));
                    }
                    if (fields.getField(DefinedFields.SEVERITY) != null) {
                        assertTrue(fields.getField(DefinedFields.SEVERITY).equals(tokens[15]));
                    }
                    if (fields.getField(DefinedFields.SERVER_IP) != null) {
                        assertTrue(fields.getField(DefinedFields.SERVER_IP).equals(tokens[16]));
                    }
                    if (fields.getField(DefinedFields.CLIENT_IP) != null) {
                        assertTrue(fields.getField(DefinedFields.CLIENT_IP).equals(tokens[19]));
                    }
                    if (fields.getField(DefinedFields.CLASS_NAME) != null) {
                        assertTrue(fields.getField(DefinedFields.CLASS_NAME).equals(tokens[20]));
                    }
                    if (fields.getField(DefinedFields.PROCESS_KEY) != null) {
                        assertTrue(fields.getField(DefinedFields.PROCESS_KEY).equals(tokens[22]));
                    }
                    if (fields.getField(DefinedFields.TARGET_ENTITY) != null) {
                        assertTrue(fields.getField(DefinedFields.TARGET_ENTITY).equals(tokens[23]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_1) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_1).equals(tokens[24]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_2) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_2).equals(tokens[25]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_3) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_3).equals(tokens[26]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_4) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_4).equals(tokens[27]));
                    }
                    break;

                case AUDIT:
                    if (fields.getField(DefinedFields.STATUS_CODE) != null) {
                        assertTrue(fields.getField(DefinedFields.STATUS_CODE).equals(tokens[8]));
                    }
                    if (fields.getField(DefinedFields.RESPONSE_CODE) != null) {
                        assertTrue(fields.getField(DefinedFields.RESPONSE_CODE).equals(tokens[9]));
                    }
                    if (fields.getField(DefinedFields.RESPONSE_DESCRIPTION) != null) {
                        assertTrue(fields.getField(DefinedFields.RESPONSE_DESCRIPTION).equals(tokens[10]));
                    }
                    if (fields.getField(DefinedFields.INSTANCE_UUID) != null) {
                        assertTrue(fields.getField(DefinedFields.INSTANCE_UUID).equals(tokens[11]));
                    }
                    if (fields.getField(DefinedFields.SEVERITY) != null) {
                        assertTrue(fields.getField(DefinedFields.SEVERITY).equals(tokens[13]));
                    }
                    if (fields.getField(DefinedFields.SERVER_IP) != null) {
                        assertTrue(fields.getField(DefinedFields.SERVER_IP).equals(tokens[14]));
                    }
                    if (fields.getField(DefinedFields.CLASS_NAME) != null) {
                        assertTrue(fields.getField(DefinedFields.CLASS_NAME).equals(tokens[18]));
                    }
                    if (fields.getField(DefinedFields.PROCESS_KEY) != null) {
                        assertTrue(fields.getField(DefinedFields.PROCESS_KEY).equals(tokens[20]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_1) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_1).equals(tokens[21]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_2) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_2).equals(tokens[22]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_3) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_3).equals(tokens[23]));
                    }
                    if (fields.getField(DefinedFields.CUSTOM_4) != null) {
                        assertTrue(fields.getField(DefinedFields.CUSTOM_4).equals(tokens[24]));
                    }
                    break;
                default:
                    break;
            }
        }

        private void validateMetricsMsg(String value) {
            String[] tokens = tokenizeLogString();
            assertTrue("Unexpected message in log string", value.equals(tokens[METRICS_MSG_INDEX]));
        }

        private void validateMetricsRespStatus(String code, String codeStr) {
            String[] tokens = tokenizeLogString();
            assertTrue("Unexpected resp code in log string",
                code.equals(tokens[METRICS_RESP_CODE_INDEX]));
            assertTrue("Unexpected resp string in log string",
                codeStr.equals(tokens[METRICS_RESP_STRING_INDEX]));
        }

        private void validateMetricsRequestId(String value) {
            String[] tokens = tokenizeLogString();
            assertTrue("Unexpected req id in log string", value.equals(tokens[METRICE_TRANS_ID_INDEX]));
        }

        private void validateAuditMsg(String value) {
            String[] tokens = tokenizeLogString();
            assertTrue("Unexpected message in log string", value.equals(tokens[AUDIT_MSG_INDEX]));
        }

        private void validateAuditRespStatus(String code, String codeStr) {
            String[] tokens = tokenizeLogString();
            assertTrue("Unexpected resp code in log string", code.equals(tokens[AUDIT_RESP_CODE_INDEX]));
            assertTrue("Unexpected resp string in log string",
                codeStr.equals(tokens[AUDIT_RESP_STRING_INDEX]));
        }

        public void validateLogLevel(EELFLogger.Level expectedLevel) {

            assertEquals("Unexpected log level", expectedLevel, logLevel);
        }

        /** This method breaks up the log string into individual tokenized fields,
         * delimited by the '|' character.
         *
         * @return - Array of log message tokens. */
        private String[] tokenizeLogString() {
            System.out.println("\n\n---\n" + logMessage + "\n-------");
            return logMessage.split("\\|");
        }

        @Override
        public String getName() {

            throw new UnsupportedOperationException("Unimplemented method 'getName'");
        }

        @Override
        public void trace(String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void trace(String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public boolean isTraceEnabled(Marker marker) {

            throw new UnsupportedOperationException("Unimplemented method 'isTraceEnabled'");
        }

        @Override
        public void trace(Marker marker, String msg) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void trace(Marker marker, String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void trace(Marker marker, String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void trace(Marker marker, String format, Object... argArray) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void trace(Marker marker, String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void debug(String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void debug(String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public boolean isDebugEnabled(Marker marker) {

            throw new UnsupportedOperationException("Unimplemented method 'isDebugEnabled'");
        }

        @Override
        public void debug(Marker marker, String msg) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void debug(Marker marker, String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void debug(Marker marker, String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void debug(Marker marker, String format, Object... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void debug(Marker marker, String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void info(String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public boolean isInfoEnabled(Marker marker) {

            throw new UnsupportedOperationException("Unimplemented method 'isInfoEnabled'");
        }

        @Override
        public void info(Marker marker, String msg) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(Marker marker, String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(Marker marker, String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(Marker marker, String format, Object... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void info(Marker marker, String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void warn(String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void warn(String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public boolean isWarnEnabled(Marker marker) {

            throw new UnsupportedOperationException("Unimplemented method 'isWarnEnabled'");
        }

        @Override
        public void warn(Marker marker, String msg) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void warn(Marker marker, String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void warn(Marker marker, String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void warn(Marker marker, String format, Object... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void warn(Marker marker, String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void error(String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void error(String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public boolean isErrorEnabled(Marker marker) {

            throw new UnsupportedOperationException("Unimplemented method 'isErrorEnabled'");
        }

        @Override
        public void error(Marker marker, String msg) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void error(Marker marker, String format, Object arg) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void error(Marker marker, String format, Object arg1, Object arg2) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void error(Marker marker, String format, Object... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void error(Marker marker, String msg, Throwable t) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void warn(Locale locale, EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void info(Locale locale, EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void debug(Locale locale, EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void error(Locale locale, EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void trace(Locale locale, EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void warn(Locale locale, EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void info(Locale locale, EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void debug(Locale locale, EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void error(Locale locale, EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void trace(Locale locale, EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void warn(EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void info(EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void debug(EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void error(EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void trace(EELFResolvableResourceEnum resource, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }

        @Override
        public void warn(EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'warn'");
        }

        @Override
        public void info(EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'info'");
        }

        @Override
        public void debug(EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'debug'");
        }

        @Override
        public void error(EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'error'");
        }

        @Override
        public void trace(EELFResolvableResourceEnum resource, Throwable th, String... arguments) {

            throw new UnsupportedOperationException("Unimplemented method 'trace'");
        }
    }
}