2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.logging.api;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
22 import org.junit.Test;
25 * Unit-testing metrics builder and structure.
30 public class MetricsDataTest {
33 public void allMetricsPropertiesReadWhenPopulated() {
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";
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();
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());
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());