blob: 7012ee806992aed8cc06fe834698e418a4406e18 [file] [log] [blame]
boyoung21c5f5f42018-09-27 20:29:41 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacktelemetry.config;
17
18import com.google.common.collect.ImmutableMap;
19import com.google.common.testing.EqualsTester;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.openstacktelemetry.api.config.PrometheusTelemetryConfig;
23
24import java.util.Map;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
boyoung2a8549d22018-11-23 20:42:37 +090029import static org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PROMETHEUS_EXPORTER_PORT_DEFAULT;
30import static org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PROMETHEUS_EXPORTER_ADDRESS_DEFAULT;
boyoung21c5f5f42018-09-27 20:29:41 +090031
32/**
33 * Unit tests for DefaultPrometheusTelemetryConfig class.
34 */
35public class DefaultPrometheusTelemetryConfigTest {
36
boyoung2a8549d22018-11-23 20:42:37 +090037 private static final String IP_ADDRESS_1 = PROP_PROMETHEUS_EXPORTER_ADDRESS_DEFAULT;
boyoung21c5f5f42018-09-27 20:29:41 +090038 private static final String IP_ADDRESS_2 = "10.10.1.2";
39
boyoung2a8549d22018-11-23 20:42:37 +090040 private static final int PORT_1 = PROP_PROMETHEUS_EXPORTER_PORT_DEFAULT;
41 private static final int PORT_2 = PROP_PROMETHEUS_EXPORTER_PORT_DEFAULT + 1;
boyoung21c5f5f42018-09-27 20:29:41 +090042
43 private static final Map<String, Object> CONFIG_MAP_1 =
44 ImmutableMap.of("key1", "value1");
45 private static final Map<String, Object> CONFIG_MAP_2 =
46 ImmutableMap.of("key2", "value2");
47
48 private PrometheusTelemetryConfig config1;
49 private PrometheusTelemetryConfig sameAsConfig1;
50 private PrometheusTelemetryConfig config2;
51
52 /**
53 * Initial setup for this unit test.
54 */
55 @Before
56 public void setup() {
57
58 PrometheusTelemetryConfig.Builder builder1 =
59 new DefaultPrometheusTelemetryConfig.DefaultBuilder();
60 PrometheusTelemetryConfig.Builder builder2 =
61 new DefaultPrometheusTelemetryConfig.DefaultBuilder();
62 PrometheusTelemetryConfig.Builder builder3 =
63 new DefaultPrometheusTelemetryConfig.DefaultBuilder();
64
65 config1 = builder1
66 .withAddress(IP_ADDRESS_1)
67 .withPort(PORT_1)
68 .withConfigMap(CONFIG_MAP_1)
69 .build();
70
71 sameAsConfig1 = builder2
72 .withAddress(IP_ADDRESS_1)
73 .withPort(PORT_1)
74 .withConfigMap(CONFIG_MAP_1)
75 .build();
76
77 config2 = builder3
78 .withAddress(IP_ADDRESS_2)
79 .withPort(PORT_2)
80 .withConfigMap(CONFIG_MAP_2)
81 .build();
82 }
83
84 /**
85 * Tests class immutability.
86 */
87 @Test
88 public void testImmutability() {
89 assertThatClassIsImmutable(DefaultPrometheusTelemetryConfig.class);
90 }
91
92 /**
93 * Tests object equality.
94 */
95 @Test
96 public void testEquality() {
97 new EqualsTester()
98 .addEqualityGroup(config1, sameAsConfig1)
99 .addEqualityGroup(config2).testEquals();
100 }
101
102 /**
103 * Tests object construction.
104 */
105 @Test
106 public void testConstruction() {
107 PrometheusTelemetryConfig config = config1;
108
109 assertThat(config.address(), is(IP_ADDRESS_1));
110 assertThat(config.port(), is(PORT_1));
111 assertThat(config.configMap(), is(CONFIG_MAP_1));
112 }
113}