aboutsummaryrefslogtreecommitdiffstats
path: root/appc-metric
diff options
context:
space:
mode:
authorAbhai Singh <Abhai.Singh@amdocs.com>2017-08-29 14:44:41 +0530
committerSkip Wonnell <skip@att.com>2017-08-30 16:03:56 +0000
commit9a1e7032fae218bd820dc06436a52173fbae7d6e (patch)
treebf5308de97f40dc4491cffc5fd393d5deef02ad0 /appc-metric
parent17c829c6d98c96a5aca2ebbedbd2bfb790948772 (diff)
Increase unit test coverage of appc-metric module
Updated test class TestMetricServiceImpl with unit test cases Change-Id: I4290f426259b837ad4db63efd8d64ba9989843cd Issue-ID:APPC-176 Signed-off-by: Abhai Singh <Abhai.Singh@amdocs.com>
Diffstat (limited to 'appc-metric')
-rw-r--r--appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java132
1 files changed, 129 insertions, 3 deletions
diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java
index 0e54af8e7..f35410e09 100644
--- a/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java
+++ b/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java
@@ -25,11 +25,21 @@
package org.openecomp.appc.metricservice;
import org.junit.Assert;
import org.junit.Test;
-import org.openecomp.appc.metricservice.MetricRegistry;
import org.openecomp.appc.metricservice.impl.MetricServiceImpl;
+import org.openecomp.appc.metricservice.metric.MetricType;
+import org.openecomp.appc.metricservice.metric.PrimitiveCounter;
+import org.openecomp.appc.metricservice.metric.DmaapRequestCounterMetric;
+import org.openecomp.appc.metricservice.metric.DispatchingFuntionMetric;
+import org.openecomp.appc.metricservice.metric.impl.DefaultPrimitiveCounter;
+import org.openecomp.appc.metricservice.metric.impl.DmaapRequestCounterMetricImpl;
+import org.openecomp.appc.metricservice.metric.impl.DispatchingFuntionMetricImpl;
+import org.openecomp.appc.metricservice.metric.impl.DispatchingFunctionCounterBuilderImpl;
+import org.openecomp.appc.metricservice.metric.impl.DmaapRequestCounterBuilderImpl;
+import org.openecomp.appc.metricservice.metric.impl.PrimitiveCounterBuilderImpl;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
public class TestMetricServiceImpl {
@@ -39,5 +49,121 @@ public class TestMetricServiceImpl {
metricServiceImpl.createRegistry("anyName");
MetricRegistry metricRegistry = metricServiceImpl.registry("anyName");
Assert.assertNotNull(metricRegistry);
+ Assert.assertTrue(metricServiceImpl.getAllRegistry().keySet().contains("anyName"));
}
+
+ @Test
+ public void testDefaultPrimitiveCounter(){
+ DefaultPrimitiveCounter df= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER);
+ df.increment();
+ Assert.assertEquals(1, df.value());
+ df.increment(25);
+ Assert.assertEquals(2, df.value());
+ df.decrement();
+ Assert.assertEquals(1, df.value());
+ Assert.assertNotNull(df.getLastModified());
+ Assert.assertEquals("TEST",df.name());
+ Assert.assertEquals(MetricType.COUNTER,df.type());
+ df.reset();
+ Assert.assertEquals(0,df.value());
+ Assert.assertNotNull(df.getMetricsOutput());
+
+ }
+
+ @Test
+ public void testDefaultPrimitiveCounterWithThreeArgsConstructor(){
+ DefaultPrimitiveCounter obj= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER,3);
+ obj.increment();
+ Assert.assertEquals(4, obj.value());
+ obj.increment(25);
+ Assert.assertEquals(5, obj.value());
+ obj.decrement();
+ Assert.assertEquals(4, obj.value());
+ Assert.assertNotNull(obj.getLastModified());
+ Assert.assertEquals("TEST",obj.name());
+ Assert.assertEquals(MetricType.COUNTER,obj.type());
+ obj.reset();
+ Assert.assertEquals(0,obj.value());
+ Assert.assertNotNull(obj.getMetricsOutput());
+ }
+
+ @Test
+ public void testDmaapRequestCounterMetricImpl() {
+
+ DmaapRequestCounterMetricImpl obj =new DmaapRequestCounterMetricImpl("TEST",MetricType.COUNTER,7,1);
+ String date = getCurrentDate();
+
+ obj.incrementPublishedMessage();
+ obj.incrementRecievedMessage();
+ Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages")));
+ Assert.assertEquals(8,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages")));
+ Assert.assertEquals(date+"[8],[2]",obj.value());
+ Assert.assertNotNull(obj.getLastModified());
+ Assert.assertEquals("TEST",obj.name());
+ Assert.assertEquals(MetricType.COUNTER,obj.type());
+ obj.reset();
+ Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages")));
+ Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages")));
+
+ }
+
+ @Test
+ public void testDispatchingFuntionMetricImpl() {
+
+ DispatchingFuntionMetricImpl obj= new DispatchingFuntionMetricImpl("TEST",MetricType.COUNTER,7,1);
+ String date = getCurrentDate();
+
+ obj.incrementAcceptedRequest();
+ obj.incrementRejectedRequest();
+ Assert.assertEquals(10,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages")));
+ Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages")));
+ Assert.assertEquals(date+"[8,2]@10",obj.value());
+ Assert.assertNotNull(obj.getLastModified());
+ Assert.assertEquals("TEST",obj.name());
+ Assert.assertEquals(MetricType.COUNTER,obj.type());
+ obj.reset();
+ Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages")));
+ Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages")));
+
+
+ }
+
+ @Test
+ public void testDispatchingFunctionCounterBuilderImpl(){
+ DispatchingFunctionCounterBuilderImpl obj=new DispatchingFunctionCounterBuilderImpl();
+ String date = getCurrentDate();
+ DispatchingFuntionMetric metric=obj.withName("TEST").withType(MetricType.COUNTER).withAcceptRequestValue(7).withRejectRequestValue(2).build();
+ metric.incrementAcceptedRequest();
+ metric.incrementRejectedRequest();
+ Assert.assertEquals(date+"[8,3]@11",metric.value());
+ }
+
+ @Test
+ public void testDmaapRequestCounterBuilderImpl(){
+ DmaapRequestCounterBuilderImpl obj=new DmaapRequestCounterBuilderImpl();
+ DmaapRequestCounterMetric metric =obj.withName("TEST").withPublishedMessage(1).withRecievedMessage(21).withType(MetricType.COUNTER).build();
+ metric.incrementPublishedMessage();
+ metric.incrementRecievedMessage();
+ Assert.assertEquals(2,Integer.parseInt(metric.getMetricsOutput().get("Total Published messages")));
+ Assert.assertEquals(22,Integer.parseInt(metric.getMetricsOutput().get("Total Received messages")));
+ }
+
+ @Test
+ public void testPrimitiveCounterBuilderImpl(){
+ PrimitiveCounterBuilderImpl obj=new PrimitiveCounterBuilderImpl();
+ PrimitiveCounter counter=obj.withName("TEST").withType(MetricType.COUNTER).withValue(1).build();
+ counter.increment();
+ Assert.assertEquals(2, counter.value());
+ counter.decrement();
+ Assert.assertEquals(1, counter.value());
+ }
+
+ private String getCurrentDate() {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeZone(TimeZone.getTimeZone("UTC"));
+ SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
+ return dateFormat.format(cal.getTime());
+
+ }
+
}