boyoung2 | 1c5f5f4 | 2018-09-27 20:29:41 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstacktelemetry.config; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.openstacktelemetry.api.config.PrometheusTelemetryConfig; |
| 23 | |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 29 | import static org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROMETHEUS_EXPORTER_PORT_DEFAULT; |
| 30 | import static org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROMETHEUS_EXPORTER_ADDRESS_DEFAULT; |
boyoung2 | 1c5f5f4 | 2018-09-27 20:29:41 +0900 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Unit tests for DefaultPrometheusTelemetryConfig class. |
| 34 | */ |
| 35 | public class DefaultPrometheusTelemetryConfigTest { |
| 36 | |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 37 | private static final String IP_ADDRESS_1 = PROMETHEUS_EXPORTER_ADDRESS_DEFAULT; |
boyoung2 | 1c5f5f4 | 2018-09-27 20:29:41 +0900 | [diff] [blame] | 38 | private static final String IP_ADDRESS_2 = "10.10.1.2"; |
| 39 | |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 40 | private static final int PORT_1 = PROMETHEUS_EXPORTER_PORT_DEFAULT; |
| 41 | private static final int PORT_2 = PROMETHEUS_EXPORTER_PORT_DEFAULT + 1; |
boyoung2 | 1c5f5f4 | 2018-09-27 20:29:41 +0900 | [diff] [blame] | 42 | |
| 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 | } |