2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.logging.filter.base;
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;
37 @RunWith(MockitoJUnitRunner.class)
38 public class PayloadLoggingClientFilterTest {
41 private ClientRequestContext requestContext;
45 private PayloadLoggingClientFilter payloadLoggingClientFilter;
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);
53 assertEquals("filtered (overridden to filter)", method);
57 public void formatMethodNullHeaderTest() throws IOException, URISyntaxException {
58 when(requestContext.getMethod()).thenReturn("filtered");
59 String method = payloadLoggingClientFilter.formatMethod(requestContext);
61 assertEquals("filtered", method);
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");
70 String printHeaders = payloadLoggingClientFilter.getHeaders(headers);
72 assertEquals("{Authorization=[***REDACTED***], X-ONAP-PartnerName=[SO]}", printHeaders);