2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Modifications Copyright (C) 2019 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.metricservice.impl;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertSame;
30 import static org.junit.Assert.assertTrue;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.appc.metricservice.metric.Counter;
34 import org.onap.appc.metricservice.metric.MetricBuilderFactory;
35 import org.onap.appc.metricservice.metric.MetricType;
36 import org.onap.appc.metricservice.metric.impl.DefaultPrimitiveCounter;
37 import org.onap.appc.metricservice.metric.impl.DispatchingFuntionMetricImpl;
38 import org.onap.appc.metricservice.policy.PolicyBuilderFactory;
40 public class MetricRegistryImplTest {
42 private static final String METRIC_NAME = "METRIC_NAME";
43 private static final String COUNTER_NAME = "COUNTER_NAME";
44 private MetricRegistryImpl registry;
45 private DispatchingFuntionMetricImpl metric;
46 private DefaultPrimitiveCounter counter;
50 registry = new MetricRegistryImpl(null);
51 counter = new DefaultPrimitiveCounter(COUNTER_NAME, null);
52 metric = new DispatchingFuntionMetricImpl(METRIC_NAME, MetricType.COUNTER, 0, 0);
57 public void testRegister() {
58 assertEquals(0, registry.counters().length);
59 assertEquals(0, registry.metrics().length);
60 assertNull(registry.counter(COUNTER_NAME));
61 assertTrue(registry.register(counter));
62 assertFalse(registry.register(counter));
63 assertTrue(registry.counter(COUNTER_NAME) instanceof Counter);
64 assertSame(counter, registry.counter(COUNTER_NAME));
65 assertTrue(registry.register(metric));
66 assertSame(metric, registry.metric(METRIC_NAME));
67 assertEquals(1, registry.counters().length);
68 assertEquals(2, registry.metrics().length);
72 public void testDispose() {
73 registry.register(metric);
74 registry.register(counter);
75 assertEquals(2, registry.metrics().length);
77 assertEquals(0, registry.metrics().length);
81 public void testmetricBuilderFactory() {
82 assertTrue(registry.metricBuilderFactory() instanceof MetricBuilderFactory);
86 public void testPolicyBuilderFactory() {
87 assertTrue(registry.policyBuilderFactory() instanceof PolicyBuilderFactory);