43f913ecab86c4122a4c46701eeee2804fb82be8
[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.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
21
22 import org.junit.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 = "IP72";
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(ipAddress, data.getClientIpAddress());
49         assertEquals(end, data.getEndTime());
50         assertEquals(start, data.getStartTime());
51         assertEquals(responseCode, data.getResponseCode());
52         assertEquals(responseDescription, data.getResponseDescription());
53         assertEquals(StatusCode.COMPLETE, data.getStatusCode());
54         assertEquals(targetEntity, data.getTargetEntity());
55         assertEquals(targetVirtualEntity, data.getTargetVirtualEntity());
56
57     }
58
59     @Test
60     public void allMetricsPropertiesEmptyWhenUnpopulated() {
61         MetricsData data = MetricsData.builder().build();
62         assertEquals(0, data.getStartTime());
63         assertEquals(0, data.getEndTime());
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 }