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=========================================================
20 package org.onap.aai.aailog.filter;
22 import org.junit.After;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.Spy;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.logging.filter.base.Constants;
30 import org.onap.logging.ref.slf4j.ONAPLogConstants;
33 import javax.ws.rs.container.ContainerRequestContext;
34 import javax.ws.rs.container.ContainerResponseContext;
35 import javax.ws.rs.core.MultivaluedHashMap;
36 import javax.ws.rs.core.MultivaluedMap;
37 import javax.ws.rs.core.UriInfo;
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Mockito.when;
43 @RunWith(MockitoJUnitRunner.class)
44 public class AaiAuditLogContainerFilterTest {
46 private ContainerRequestContext containerRequest;
49 private ContainerResponseContext containerResponse;
52 private UriInfo uriInfo;
56 private AaiAuditLogContainerFilter aaiAuditFilter;
59 public void tearDown() {
63 public void partnerAndServiceNameValueTest() throws java.net.URISyntaxException {
65 MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
66 headerMap.putSingle(Constants.HttpHeaders.HEADER_FROM_APP_ID, "FROM_APP_ID_TEST");
67 when(containerRequest.getHeaders()).thenReturn(headerMap);
71 uri = new URI("https://localhost:9999/onap/aai/network/logical-link");
73 catch (java.net.URISyntaxException e) {
76 when(uriInfo.getAbsolutePath()).thenReturn(uri);
77 when(containerRequest.getUriInfo()).thenReturn(uriInfo);
79 aaiAuditFilter.filter(containerRequest);
80 assertEquals("FROM_APP_ID_TEST", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
81 assertEquals("/onap/aai/network/logical-link", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));