summaryrefslogtreecommitdiffstats
path: root/appc-metric/appc-metric-bundle/src/test
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-01-11 10:41:59 +0000
committerJoss Armstrong <joss.armstrong@ericsson.com>2019-01-11 10:42:26 +0000
commita1482e86dfea4360b1d8338ca7a0f1c5dee52b1a (patch)
tree62e51e99e3b2a883d381cc14fe4fbd6d5831bc13 /appc-metric/appc-metric-bundle/src/test
parent67279c0983c0a010e84d58a83f6bfaeefc304d95 (diff)
Add code coverage for metric-service-policy code
Increased line coverage from 0% to 79% Issue-ID: APPC-1321 Change-Id: I79f65d97055248b73da875e9591bd2c6e86afca4 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-metric/appc-metric-bundle/src/test')
-rw-r--r--appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java64
-rw-r--r--appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImplTest.java125
2 files changed, 158 insertions, 31 deletions
diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java
index c6f7fbf48..cdaf4bd1b 100644
--- a/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java
+++ b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,10 +63,10 @@ public class TestMetricServiceImpl {
df.decrement();
Assert.assertEquals(1, df.value());
Assert.assertNotNull(df.getLastModified());
- Assert.assertEquals("TEST",df.name());
- Assert.assertEquals(MetricType.COUNTER,df.type());
+ Assert.assertEquals("TEST", df.name());
+ Assert.assertEquals(MetricType.COUNTER, df.type());
df.reset();
- Assert.assertEquals(0,df.value());
+ Assert.assertEquals(0, df.value());
Assert.assertNotNull(df.getMetricsOutput());
}
@@ -79,78 +81,78 @@ public class TestMetricServiceImpl {
obj.decrement();
Assert.assertEquals(4, obj.value());
Assert.assertNotNull(obj.getLastModified());
- Assert.assertEquals("TEST",obj.name());
- Assert.assertEquals(MetricType.COUNTER,obj.type());
+ Assert.assertEquals("TEST", obj.name());
+ Assert.assertEquals(MetricType.COUNTER, obj.type());
obj.reset();
- Assert.assertEquals(0,obj.value());
+ Assert.assertEquals(0, obj.value());
Assert.assertNotNull(obj.getMetricsOutput());
}
@Test
public void testDmaapRequestCounterMetricImpl() {
- DmaapRequestCounterMetricImpl obj =new DmaapRequestCounterMetricImpl("TEST",MetricType.COUNTER,7,1);
+ 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.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());
+ 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")));
+ 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);
+ 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.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());
+ 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")));
+ 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();
+ DispatchingFunctionCounterBuilderImpl obj = new DispatchingFunctionCounterBuilderImpl();
String date = getCurrentDate();
- DispatchingFuntionMetric metric=obj.withName("TEST").withType(MetricType.COUNTER).withAcceptRequestValue(7).withRejectRequestValue(2).build();
+ 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());
+ 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();
+ 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")));
+ 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();
+ PrimitiveCounterBuilderImpl obj = new PrimitiveCounterBuilderImpl();
+ PrimitiveCounter counter = obj.withName("TEST").withType(MetricType.COUNTER).withValue(1).build();
counter.increment();
Assert.assertEquals(2, counter.value());
counter.decrement();
diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImplTest.java b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImplTest.java
new file mode 100644
index 000000000..31c23101d
--- /dev/null
+++ b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImplTest.java
@@ -0,0 +1,125 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.metricservice.policy.impl;
+
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.metricservice.Publisher;
+import org.onap.appc.metricservice.metric.Metric;
+import org.onap.appc.metricservice.metric.impl.DmaapRequestCounterMetricImpl;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+import org.junit.Assert;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(ConfigurationFactory.class)
+public class ScheduledPublishingPolicyImplTest {
+
+ private Configuration configuration = Mockito.mock(Configuration.class);
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(ConfigurationFactory.class);
+ PowerMockito.when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
+ }
+
+ @Test
+ public void testWithPeriodAndStartTime() {
+ Properties properties = new Properties();
+ properties.setProperty("schedule.policy.metric.period", "1000");
+ properties.setProperty("schedule.policy.metric.start.time", "1000");
+ Mockito.when(configuration.getProperties()).thenReturn(properties);
+ PolicyBuilderFactoryImpl builderFactory = new PolicyBuilderFactoryImpl();
+ ScheduledPolicyBuilderImpl policyBuilder = (ScheduledPolicyBuilderImpl) builderFactory.scheduledPolicyBuilder();
+ Metric[] metrics = new Metric[0];
+ policyBuilder.withMetrics(metrics);
+ ScheduledPublishingPolicyImpl publishingPolicy = (ScheduledPublishingPolicyImpl) policyBuilder.build();
+ Assert.assertEquals(0, publishingPolicy.metrics().length);
+ }
+
+ @Test
+ public void testWithPeriod() {
+ Properties properties = new Properties();
+ properties.setProperty("schedule.policy.metric.period", "1000");
+ Mockito.when(configuration.getProperties()).thenReturn(properties);
+ PolicyBuilderFactoryImpl builderFactory = new PolicyBuilderFactoryImpl();
+ ScheduledPolicyBuilderImpl policyBuilder = (ScheduledPolicyBuilderImpl) builderFactory.scheduledPolicyBuilder();
+ Metric[] metrics = new Metric[0];
+ policyBuilder.withMetrics(metrics);
+ ScheduledPublishingPolicyImpl publishingPolicy = (ScheduledPublishingPolicyImpl) policyBuilder.build();
+ Assert.assertEquals(0, publishingPolicy.metrics().length);
+ }
+
+ @Test
+ public void testWithNeither() {
+ Properties properties = new Properties();
+ Mockito.when(configuration.getProperties()).thenReturn(properties);
+ PolicyBuilderFactoryImpl builderFactory = new PolicyBuilderFactoryImpl();
+ ScheduledPolicyBuilderImpl policyBuilder = (ScheduledPolicyBuilderImpl) builderFactory.scheduledPolicyBuilder();
+ Metric[] metrics = new Metric[0];
+ policyBuilder.withMetrics(metrics);
+ policyBuilder.withPublishers(null);
+ ScheduledPublishingPolicyImpl publishingPolicy = (ScheduledPublishingPolicyImpl) policyBuilder.build();
+ Assert.assertEquals(0, publishingPolicy.metrics().length);
+
+ }
+
+ @Test
+ public void testWithNullProperties() {
+ Mockito.when(configuration.getProperties()).thenReturn(null);
+ PolicyBuilderFactoryImpl builderFactory = new PolicyBuilderFactoryImpl();
+ ScheduledPolicyBuilderImpl policyBuilder = (ScheduledPolicyBuilderImpl) builderFactory.scheduledPolicyBuilder();
+ Metric[] metrics = new Metric[0];
+ policyBuilder.withMetrics(metrics);
+ policyBuilder.withPeriod(100000);
+ policyBuilder.withStartTime(1);
+ ScheduledPublishingPolicyImpl publishingPolicy = (ScheduledPublishingPolicyImpl) policyBuilder.build();
+ Assert.assertEquals(0, publishingPolicy.metrics().length);
+ Assert.assertEquals(100000, publishingPolicy.getPeriod());
+ Assert.assertEquals(1, publishingPolicy.getStartTime());
+ }
+
+ @Test
+ public void testConstructorAndInit() {
+ Properties properties = new Properties();
+ properties.setProperty("schedule.policy.metric.period", "1000");
+ properties.setProperty("schedule.policy.metric.start.time", "1000");
+ properties.setProperty("metric.enabled" , "true");
+ Publisher publisherMock = Mockito.mock(Publisher.class);
+ Publisher[] publisherArray = new Publisher[1];
+ publisherArray[0] = publisherMock;
+ Mockito.when(configuration.getProperties()).thenReturn(properties);
+ ScheduledPublishingPolicyImpl publishingPolicy = new ScheduledPublishingPolicyImpl(1000, 1000, publisherArray, new Metric[0]);
+ Whitebox.setInternalState(publishingPolicy, "configuration", configuration);
+ publishingPolicy.init();
+ Assert.assertEquals(1, publishingPolicy.getPublishers().length);
+ }
+
+}