Increase code coverage on aai-common: aai-els-onap-logging library
[aai/aai-common.git] / aai-els-onap-logging / src / test / java / org / onap / logging / filter / base / PayloadLoggingClientFilterTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - Logging
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.logging.filter.base;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25 import java.io.IOException;
26 import java.net.URISyntaxException;
27 import javax.ws.rs.client.ClientRequestContext;
28 import javax.ws.rs.core.MultivaluedHashMap;
29 import javax.ws.rs.core.MultivaluedMap;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Spy;
35 import org.mockito.junit.MockitoJUnitRunner;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class PayloadLoggingClientFilterTest {
39
40     @Mock
41     private ClientRequestContext requestContext;
42
43     @Spy
44     @InjectMocks
45     private PayloadLoggingClientFilter payloadLoggingClientFilter;
46
47     @Test
48     public void formatMethodTest() throws IOException, URISyntaxException {
49         when(requestContext.getHeaderString("X-HTTP-Method-Override")).thenReturn("filter");
50         when(requestContext.getMethod()).thenReturn("filtered");
51         String method = payloadLoggingClientFilter.formatMethod(requestContext);
52
53         assertEquals("filtered (overridden to filter)", method);
54     }
55
56     @Test
57     public void formatMethodNullHeaderTest() throws IOException, URISyntaxException {
58         when(requestContext.getMethod()).thenReturn("filtered");
59         String method = payloadLoggingClientFilter.formatMethod(requestContext);
60
61         assertEquals("filtered", method);
62     }
63
64     @Test
65     public void getHeadersTest() {
66         MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
67         headers.add(Constants.HttpHeaders.ONAP_PARTNER_NAME, "SO");
68         headers.add("Authorization", "Test");
69
70         String printHeaders = payloadLoggingClientFilter.getHeaders(headers);
71
72         assertEquals("{Authorization=[***REDACTED***], X-ONAP-PartnerName=[SO]}", printHeaders);
73     }
74 }