43f9865018964f1597bb62d301f8832f0130c64a
[vid.git] / vid-app-common / src / test / java / org / onap / vid / logging / ApacheClientMetricInterceptorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 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
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.vid.logging;
22
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNull;
25
26 import org.apache.http.HttpResponse;
27 import org.apache.http.ProtocolVersion;
28 import org.apache.http.client.methods.HttpGet;
29 import org.apache.http.message.BasicHttpResponse;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
32
33 public class ApacheClientMetricInterceptorTest {
34
35     private ApacheClientMetricInterceptor interceptor;
36     private final String path = "https://gerrit.onap.org/r/projects/vid/branches?n=16&S=0&m=master";
37     private HttpGet request;
38     private HttpResponse response;
39
40     @BeforeMethod
41     public void before() {
42         interceptor = new ApacheClientMetricInterceptor() {};
43         request = new HttpGet(path);
44         response = new BasicHttpResponse(new ProtocolVersion("a",1,2), 200, "ok");
45     }
46
47     @Test
48     public void testAddHeader() {
49         interceptor.addHeader(request, "key", "value");
50         assertEquals(request.getFirstHeader("key").getValue(), "value");
51     }
52
53     @Test
54     public void testGetTargetServiceName() {
55         assertEquals(interceptor.getTargetServiceName(request), path);
56     }
57
58     @Test
59     public void testGetServiceName() {
60         assertEquals(interceptor.getTargetServiceName(request), path);
61     }
62
63     @Test
64     public void testGetHttpStatusCode() {
65         assertEquals(interceptor.getHttpStatusCode(response), 200);
66     }
67
68     @Test
69     public void testGetResponseCode() {
70         assertEquals(interceptor.getResponseCode(response), "200");
71     }
72
73     @Test
74     public void testGetTargetEntity() {
75         assertNull(interceptor.getTargetEntity(request));
76     }
77 }