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;
26 import java.io.IOException;
27 import java.net.URISyntaxException;
29 import javax.ws.rs.client.ClientRequestContext;
30 import javax.ws.rs.core.MultivaluedHashMap;
31 import javax.ws.rs.core.MultivaluedMap;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.Spy;
38 import org.mockito.junit.MockitoJUnitRunner;
40 @RunWith(MockitoJUnitRunner.class)
41 public class PayloadLoggingClientFilterTest {
44 private ClientRequestContext requestContext;
48 private PayloadLoggingClientFilter payloadLoggingClientFilter;
51 public void formatMethodTest() throws IOException, URISyntaxException {
52 when(requestContext.getHeaderString("X-HTTP-Method-Override")).thenReturn("filter");
53 when(requestContext.getMethod()).thenReturn("filtered");
54 String method = payloadLoggingClientFilter.formatMethod(requestContext);
56 assertEquals("filtered (overridden to filter)", method);
60 public void formatMethodNullHeaderTest() throws IOException, URISyntaxException {
61 when(requestContext.getMethod()).thenReturn("filtered");
62 String method = payloadLoggingClientFilter.formatMethod(requestContext);
64 assertEquals("filtered", method);
68 public void getHeadersTest() {
69 MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
70 headers.add(Constants.HttpHeaders.ONAP_PARTNER_NAME, "SO");
71 headers.add("Authorization", "Test");
73 String printHeaders = payloadLoggingClientFilter.getHeaders(headers);
75 assertEquals("{Authorization=[***REDACTED***], X-ONAP-PartnerName=[SO]}", printHeaders);