2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.aai.aailog.filter;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
28 import javax.ws.rs.container.ContainerRequestContext;
29 import javax.ws.rs.container.ContainerResponseContext;
30 import javax.ws.rs.core.MultivaluedHashMap;
31 import javax.ws.rs.core.MultivaluedMap;
32 import javax.ws.rs.core.UriInfo;
34 import org.junit.After;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.Spy;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.onap.logging.filter.base.Constants;
42 import org.onap.logging.ref.slf4j.ONAPLogConstants;
45 @RunWith(MockitoJUnitRunner.class)
46 public class AaiAuditLogContainerFilterTest {
48 private ContainerRequestContext containerRequest;
51 private ContainerResponseContext containerResponse;
54 private UriInfo uriInfo;
58 private AaiAuditLogContainerFilter aaiAuditFilter;
61 public void tearDown() {
66 public void partnerAndServiceNameValueTest() throws java.net.URISyntaxException {
68 MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
69 headerMap.putSingle(Constants.HttpHeaders.HEADER_FROM_APP_ID, "FROM_APP_ID_TEST");
70 when(containerRequest.getHeaders()).thenReturn(headerMap);
74 uri = new URI("https://localhost:9999/onap/aai/network/logical-link");
75 } catch (java.net.URISyntaxException e) {
78 when(uriInfo.getAbsolutePath()).thenReturn(uri);
79 when(containerRequest.getUriInfo()).thenReturn(uriInfo);
81 aaiAuditFilter.filter(containerRequest);
82 assertEquals("FROM_APP_ID_TEST", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
83 assertEquals("/onap/aai/network/logical-link", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));