aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils/src/test/java/org/onap
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-02-05 16:05:50 -0600
committerjhh <jorge.hernandez-herrero@att.com>2021-02-08 13:24:08 -0600
commit13ab17b2050ecfe5265c8fc347fa0960bac185d7 (patch)
tree3cff8341b304a674992d3b2ad4426b69b45aab1f /policy-utils/src/test/java/org/onap
parent208be1c545895cf61bc38fbc7bc5e9e45d085016 (diff)
pull generic code from mdctransaction into metric
created generic metric classes that would be used now for 2 purposes: 1) existing logging framework of metrics and transactions, 2) generic metric tracking to be use to report pdp statistics. Issue-ID: POLICY-3033 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I8f5d773f27871e19c8796d1fe2f3972b4c21fe67 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-utils/src/test/java/org/onap')
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/metrics/MetricTest.java192
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/metrics/TransMetricTest.java69
2 files changed, 261 insertions, 0 deletions
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/metrics/MetricTest.java b/policy-utils/src/test/java/org/onap/policy/drools/metrics/MetricTest.java
new file mode 100644
index 00000000..5a5965c4
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/metrics/MetricTest.java
@@ -0,0 +1,192 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.metrics;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.text.SimpleDateFormat;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Date;
+import org.junit.Test;
+
+public class MetricTest {
+
+ @Test
+ public void testPojo() {
+ PojoClass metric = PojoClassFactory.getPojoClass(Metric.class);
+ Validator val = ValidatorBuilder
+ .create()
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+ val.validate(metric);
+ }
+
+ @Test
+ public void testEndTimeSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getEndTime());
+ metric.setEndTime(null);
+ assertNotNull(metric.getEndTime());
+ }
+
+ @Test
+ public void testStartTimeSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getStartTime());
+ metric.setStartTime(null);
+ assertNotNull(metric.getStartTime());
+ }
+
+ @Test
+ public void testElapsedTimeSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getElapsedTime());
+ metric.setElapsedTime(null);
+ assertNull(metric.getElapsedTime());
+
+ Instant start = Instant.now();
+ metric.setStartTime(start);
+ metric.setElapsedTime(null);
+ assertNull(metric.getElapsedTime());
+
+ Instant end = Instant.now();
+ metric.setEndTime(end);
+ metric.setElapsedTime(null);
+ assertNotNull(metric.getElapsedTime());
+ Long duration = Duration.between(start, end).toMillis();
+ assertEquals(duration, metric.getElapsedTime());
+ }
+
+ @Test
+ public void testInvocationIdSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getInvocationId());
+ metric.setInvocationId(null);
+ assertNotNull(metric.getInvocationId());
+ }
+
+ @Test
+ public void testServiceNameSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getServiceName());
+ metric.setServiceName(null);
+ assertEquals(Metric.HOST_TYPE, metric.getServiceName());
+ }
+
+ @Test
+ public void testInstanceUuidSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getInstanceUuid());
+ metric.setInstanceUuid(null);
+ assertNotNull(metric.getInstanceUuid());
+ }
+
+ @Test
+ public void testRequestIdSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getRequestId());
+ metric.setRequestId(null);
+ assertNotNull(metric.getRequestId());
+ }
+
+ @Test
+ public void testPartnerSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getPartner());
+ metric.setPartner(null);
+ assertEquals(Metric.HOST_TYPE, metric.getPartner());
+ }
+
+ @Test
+ public void testServerNameSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getServerName());
+ metric.setServerName(null);
+ assertEquals(Metric.HOSTNAME, metric.getServerName());
+ }
+
+ @Test
+ public void testServerFqdnSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getServerFqdn());
+ metric.setServerFqdn(null);
+ assertEquals(Metric.HOSTNAME, metric.getServerFqdn());
+ }
+
+ @Test
+ public void testVirtualServerNameSetter() {
+ Metric metric = new Metric();
+
+ assertNull(metric.getVirtualServerName());
+ metric.setVirtualServerName(null);
+ assertEquals(Metric.HOSTNAME, metric.getVirtualServerName());
+ }
+
+ @Test
+ public void testEqualsToString() {
+ Metric metric1 = new Metric();
+ Metric metric2 = new Metric();
+
+ assertEquals(metric1, metric2);
+
+ metric1.setRequestId(null);
+ assertNotEquals(metric1, metric2);
+
+ metric1.setRequestId("a");
+ metric2.setRequestId("a");
+ assertEquals(metric1, metric2);
+
+ assertThat(metric1.toString()).startsWith("Metric");
+ }
+
+ @Test
+ public void testToTimestamp() {
+ Instant now = Instant.now();
+ assertEquals(new SimpleDateFormat(Metric.DATE_FORMAT).format(Date.from(now)), Metric.toTimestamp(now));
+ }
+} \ No newline at end of file
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/metrics/TransMetricTest.java b/policy-utils/src/test/java/org/onap/policy/drools/metrics/TransMetricTest.java
new file mode 100644
index 00000000..e3e8fb79
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/metrics/TransMetricTest.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.metrics;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import org.junit.Test;
+
+public class TransMetricTest {
+
+ @Test
+ public void testPojo() {
+ PojoClass metric = PojoClassFactory.getPojoClass(TransMetric.class);
+ Validator val = ValidatorBuilder
+ .create()
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+ val.validate(metric);
+ }
+
+ @Test
+ public void testEqualsToString() {
+ TransMetric trans1 = new TransMetric();
+ TransMetric trans2 = new TransMetric();
+
+ assertEquals(trans1, trans2);
+
+ trans1.setRequestId(null);
+ assertNotEquals(trans1, trans2);
+
+ trans1.setRequestId("a");
+ trans2.setRequestId("a");
+ assertEquals(trans1, trans2);
+
+ assertThat(trans1.toString()).startsWith("TransMetric");
+ }
+
+} \ No newline at end of file