a3c8b1039a847f3b72a93d411707b2c94cb2e5c0
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.logging.api;
18
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertNull;
21
22 import org.testng.annotations.Test;
23
24 /**
25  * Unit-testing metrics builder and structure.
26  *
27  * @author evitaliy
28  * @since 04 Mar 18
29  */
30 public class MetricsDataTest {
31
32     @Test
33     public void allMetricsPropertiesReadWhenPopulated() {
34
35         final long start = System.currentTimeMillis();
36         final long end = start + 1000;
37         final String responseCode = "Metrics-Response-Code";
38         final String responseDescription = "Metrics-Response-Description";
39         final String ipAddress = "10.56.20.72";
40         final String targetEntity = "Metrics-Target-Entity";
41         final String targetVirtualEntity = "Metrics-Target-Virtual-Entity";
42
43         MetricsData data = MetricsData.builder().startTime(start).endTime(end).statusCode(StatusCode.COMPLETE)
44                                       .responseCode(responseCode).responseDescription(responseDescription)
45                                       .clientIpAddress(ipAddress).targetEntity(targetEntity)
46                                       .targetVirtualEntity(targetVirtualEntity).build();
47
48         assertEquals(data.getClientIpAddress(), ipAddress);
49         assertEquals(data.getEndTime(), end);
50         assertEquals(data.getStartTime(), start);
51         assertEquals(data.getResponseCode(), responseCode);
52         assertEquals(data.getResponseDescription(), responseDescription);
53         assertEquals(data.getStatusCode(), StatusCode.COMPLETE);
54         assertEquals(data.getTargetEntity(), targetEntity);
55         assertEquals(data.getTargetVirtualEntity(), targetVirtualEntity);
56
57     }
58
59     @Test
60     public void allMetricsPropertiesEmptyWhenUnpopulated() {
61         MetricsData data = MetricsData.builder().build();
62         assertEquals(data.getStartTime(), 0);
63         assertEquals(data.getEndTime(), 0);
64         assertNull(data.getClientIpAddress());
65         assertNull(data.getResponseCode());
66         assertNull(data.getResponseDescription());
67         assertNull(data.getStatusCode());
68         assertNull(data.getTargetEntity());
69         assertNull(data.getTargetVirtualEntity());
70     }
71 }