63ead272723c9952e7350197f514b92a5f72a5cb
[logging-analytics.git] / reference / slf4j-reference / src / test / java / org / onap / logging / ref / slf4j / analysis / LogEntryTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
6  * All rights reserved.
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.logging.ref.slf4j.analysis;
23
24 import java.util.Map;
25
26 import org.slf4j.event.Level;
27 import org.testng.annotations.Test;
28
29 import static org.hamcrest.MatcherAssert.assertThat;
30 import static org.hamcrest.core.Is.is;
31 import static org.hamcrest.core.IsNull.notNullValue;
32
33 public class LogEntryTest {
34
35     @Test
36     public void testLogEntry() {
37
38         final String eg = "2018-05-07T16:45:53.056Z\tpool-1-thread-1\tINFO"
39             + "\torg.onap.logging.ref.slf4j.component.gamma.ComponentGamma\tInstanceUUID=fa8dd337-6991-4535-a069-ca552466d972,"
40             + " RequestID=46161759-1b92-40a4-a408-800e0d62dd9e, ServiceName=service.alpha, EntryTimestamp=2018-05-08T02:45:53.056,"
41             + " InvocationID=aac8fec9-498c-42a2-936b-38f5c0f5ca82, PartnerName=service.beta, ClientIPAddress=127.0.0.1,"
42             + " ServerFQDN=localhost\t\t\tENTRY\t\n";
43
44         final LogEntry parsed = new LogEntry(eg);
45         assertThat(parsed.getTimestamp(), notNullValue());
46         assertThat(parsed.getThread(), is("pool-1-thread-1"));
47         assertThat(parsed.getLevel(), is(Level.INFO));
48         assertThat(parsed.getLogger(), is("org.onap.logging.ref.slf4j.component.gamma.ComponentGamma"));
49         assertThat(parsed.getMDCs().get("ServiceName"), is("service.alpha"));
50         assertThat(parsed.getMDCs().get("PartnerName"), is("service.beta"));
51         assertThat(parsed.getMessage(), is(""));
52         assertThat(parsed.getMarkers(), is("ENTRY"));
53         assertThat(parsed.getException(), is(""));
54
55     }
56
57     @Test
58     public void testParseMDCsEmpty() {
59         final Map<String, String> map = LogEntry.parseMDCs("");
60         assertThat(map.size(), is(0));
61     }
62
63     @Test
64     public void testParseMDCs() {
65         final Map<String, String> map = LogEntry.parseMDCs("A=B, C=D , D = F ");
66         assertThat(map.get("A"), is("B"));
67         assertThat(map.get("C"), is("D"));
68         assertThat(map.get("D"), is("F"));
69         assertThat(map.size(), is(3));
70     }
71 }