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 javax.ws.rs.container.ContainerRequestContext;
27 import javax.ws.rs.container.ContainerResponseContext;
28 import javax.ws.rs.core.MultivaluedHashMap;
29 import javax.ws.rs.core.MultivaluedMap;
30 import javax.ws.rs.core.UriInfo;
32 import org.junit.After;
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;
39 import org.onap.logging.ref.slf4j.ONAPLogConstants;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 @RunWith(MockitoJUnitRunner.class)
45 public class AuditLogContainerFilterTest {
46 protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class);
49 private ContainerRequestContext containerRequest;
52 private ContainerResponseContext containerResponse;
55 private UriInfo uriInfo;
59 private AuditLogContainerFilter auditLogContainerFilter;
62 public void tearDown() {
67 public void filterTest() {
68 MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
69 headerMap.putSingle(ONAPLogConstants.Headers.REQUEST_ID, "e3b08fa3-535f-4c1b-8228-91318d2bb4ee");
70 when(containerRequest.getHeaders()).thenReturn(headerMap);
71 when(uriInfo.getPath()).thenReturn("onap/so/serviceInstances");
72 when(containerRequest.getUriInfo()).thenReturn(uriInfo);
73 auditLogContainerFilter.filter(containerRequest);
75 assertEquals("e3b08fa3-535f-4c1b-8228-91318d2bb4ee", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
76 assertEquals("onap/so/serviceInstances", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));
77 assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
81 public void getResponseCodeTest() {
82 when(containerResponse.getStatus()).thenReturn(200);
83 int responseCode = auditLogContainerFilter.getResponseCode(containerResponse);
85 assertEquals(200, responseCode);