Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-els-onap-logging / src / test / java / org / onap / aai / aailog / filter / AaiAuditLogContainerFilterTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.aailog.filter;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25
26 import java.net.URI;
27
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;
33
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;
43 import org.slf4j.MDC;
44
45 @RunWith(MockitoJUnitRunner.class)
46 public class AaiAuditLogContainerFilterTest {
47     @Mock
48     private ContainerRequestContext containerRequest;
49
50     @Mock
51     private ContainerResponseContext containerResponse;
52
53     @Mock
54     private UriInfo uriInfo;
55
56     @Spy
57     @InjectMocks
58     private AaiAuditLogContainerFilter aaiAuditFilter;
59
60     @After
61     public void tearDown() {
62         MDC.clear();
63     }
64
65     @Test
66     public void partnerAndServiceNameValueTest() throws java.net.URISyntaxException {
67
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);
71
72         URI uri = null;
73         try {
74             uri = new URI("https://localhost:9999/onap/aai/network/logical-link");
75         } catch (java.net.URISyntaxException e) {
76             throw e;
77         }
78         when(uriInfo.getAbsolutePath()).thenReturn(uri);
79         when(containerRequest.getUriInfo()).thenReturn(uriInfo);
80
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));
84     }
85
86 }