summaryrefslogtreecommitdiffstats
path: root/appc-metric/appc-metric-bundle
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-21 19:16:35 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-22 18:18:43 +0000
commit57293e84a0aa7405c9688448483d811d707e199a (patch)
treeb486d3d72138f8c998f18b741470c15ad9235742 /appc-metric/appc-metric-bundle
parent6c2b81d1d39e734435cabd66518fff26bcd49aec (diff)
Test coverage in MetricRegistryImpl
Added test coverage for MetricRegistryImpl Issue-ID: APPC-1478 Change-Id: I91eff5418ec14d294fa80af3d6d7025338b82072 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-metric/appc-metric-bundle')
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java16
-rw-r--r--appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/impl/MetricRegistryImplTest.java60
2 files changed, 65 insertions, 11 deletions
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java
index af05285d0..48d1c6fac 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications 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.
@@ -38,7 +40,7 @@ import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl;
public class MetricRegistryImpl implements MetricRegistry {
private String name;
- private Map<String,Metric> concurrentMetricMap=new ConcurrentHashMap<String,Metric>();
+ private Map<String, Metric> concurrentMetricMap = new ConcurrentHashMap<>();
public MetricRegistryImpl(String name) {
this.name = name;
@@ -46,11 +48,7 @@ public class MetricRegistryImpl implements MetricRegistry {
@Override
public boolean register(Metric metric) {
- if(concurrentMetricMap.get(metric.name())==null){
- concurrentMetricMap.put(metric.name(),metric);
- return true;
- }
- return false;
+ return (concurrentMetricMap.putIfAbsent(metric.name(), metric) == null);
}
@Override
@@ -70,11 +68,7 @@ public class MetricRegistryImpl implements MetricRegistry {
@Override
public Counter counter(String value) {
- if(concurrentMetricMap.get(value)!=null )
- return (Counter)concurrentMetricMap.get(value) ;
- else
- return null;
-
+ return (Counter)concurrentMetricMap.get(value);
}
@Override
diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/impl/MetricRegistryImplTest.java b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/impl/MetricRegistryImplTest.java
new file mode 100644
index 000000000..09e5ba954
--- /dev/null
+++ b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/impl/MetricRegistryImplTest.java
@@ -0,0 +1,60 @@
+/*
+ * ============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.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.metricservice.metric.Counter;
+import org.onap.appc.metricservice.metric.Metric;
+import org.onap.appc.metricservice.metric.impl.DefaultPrimitiveCounter;
+
+public class MetricRegistryImplTest {
+
+ private static final String NAME = "NAME";
+ private MetricRegistryImpl registry;
+ @Before
+ public void setup() {
+ registry = new MetricRegistryImpl(null);
+ }
+
+ @Test
+ public void testRegister() {
+ Metric metric = new DefaultPrimitiveCounter(NAME, null);
+ assertNull(registry.counter(NAME));
+ assertTrue(registry.register(metric));
+ assertFalse(registry.register(metric));
+ assertTrue(registry.counter(NAME) instanceof Counter);
+ assertSame(metric, registry.metric(NAME));
+ }
+
+ @Test
+ public void testCounter() {
+ registry.dispose();
+ assertEquals(0, registry.metrics().length);
+ }
+
+}