2 * ============LICENSE_START=======================================================
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
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.vid.logging;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNull;
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;
33 public class ApacheClientMetricInterceptorTest {
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;
41 public void before() {
42 interceptor = new ApacheClientMetricInterceptor() {};
43 request = new HttpGet(path);
44 response = new BasicHttpResponse(new ProtocolVersion("a",1,2), 200, "ok");
48 public void testAddHeader() {
49 interceptor.addHeader(request, "key", "value");
50 assertEquals(request.getFirstHeader("key").getValue(), "value");
54 public void testGetTargetServiceName() {
55 assertEquals(interceptor.getTargetServiceName(request), path);
59 public void testGetServiceName() {
60 assertEquals(interceptor.getTargetServiceName(request), path);
64 public void testGetHttpStatusCode() {
65 assertEquals(interceptor.getHttpStatusCode(response), 200);
69 public void testGetResponseCode() {
70 assertEquals(interceptor.getResponseCode(response), "200");
74 public void testGetTargetEntity() {
75 assertNull(interceptor.getTargetEntity(request));