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 javax.ws.rs.container.ContainerRequestContext;
26 import javax.ws.rs.container.ContainerResponseContext;
27 import javax.ws.rs.core.MultivaluedHashMap;
28 import javax.ws.rs.core.MultivaluedMap;
29 import javax.ws.rs.core.UriInfo;
30 import org.junit.After;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.Spy;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.logging.ref.slf4j.ONAPLogConstants;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 @RunWith(MockitoJUnitRunner.class)
43 public class AuditLogContainerFilterTest {
44 protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class);
47 private ContainerRequestContext containerRequest;
50 private ContainerResponseContext containerResponse;
53 private UriInfo uriInfo;
57 private AuditLogContainerFilter auditLogContainerFilter;
60 public void tearDown() {
66 public void filterTest() {
67 MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
68 headerMap.putSingle(ONAPLogConstants.Headers.REQUEST_ID, "e3b08fa3-535f-4c1b-8228-91318d2bb4ee");
69 when(containerRequest.getHeaders()).thenReturn(headerMap);
70 when(uriInfo.getPath()).thenReturn("onap/so/serviceInstances");
71 when(containerRequest.getUriInfo()).thenReturn(uriInfo);
72 auditLogContainerFilter.filter(containerRequest);
74 assertEquals("e3b08fa3-535f-4c1b-8228-91318d2bb4ee", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
75 assertEquals("onap/so/serviceInstances", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));
76 assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
80 public void getResponseCodeTest() {
81 when(containerResponse.getStatus()).thenReturn(200);
82 int responseCode = auditLogContainerFilter.getResponseCode(containerResponse);
84 assertEquals(200, responseCode);