Jian Li | 52c1122 | 2018-06-07 11:39:17 +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.InfluxDbTelemetryConfig; |
| 23 | |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for DefaultInfluxDbTelemetryConfig class. |
| 31 | */ |
Jian Li | 3db9085 | 2018-06-10 22:29:16 +0900 | [diff] [blame] | 32 | public final class DefaultInfluxDbTelemetryConfigTest { |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 33 | |
| 34 | private static final String IP_ADDRESS_1 = "10.10.10.1"; |
| 35 | private static final String IP_ADDRESS_2 = "20.20.20.1"; |
| 36 | |
| 37 | private static final int PORT_1 = 80; |
| 38 | private static final int PORT_2 = 8080; |
| 39 | |
| 40 | private static final String DATABASE_1 = "database1"; |
| 41 | private static final String DATABASE_2 = "database2"; |
| 42 | |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame^] | 43 | private static final String MEASUREMENT_1 = "measurement1"; |
| 44 | private static final String MEASUREMENT_2 = "measurement2"; |
| 45 | |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 46 | private static final String USERNAME_1 = "username1"; |
| 47 | private static final String USERNAME_2 = "username2"; |
| 48 | |
| 49 | private static final String PASSWORD_1 = "password1"; |
| 50 | private static final String PASSWORD_2 = "password2"; |
| 51 | |
| 52 | private static final boolean ENABLE_BATCH_1 = true; |
| 53 | private static final boolean ENABLE_BATCH_2 = false; |
| 54 | |
| 55 | private static final Map<String, Object> CONFIG_MAP_1 = |
| 56 | ImmutableMap.of("key1", "value1"); |
| 57 | private static final Map<String, Object> CONFIG_MAP_2 = |
| 58 | ImmutableMap.of("key2", "value2"); |
| 59 | |
| 60 | private InfluxDbTelemetryConfig config1; |
| 61 | private InfluxDbTelemetryConfig sameAsConfig1; |
| 62 | private InfluxDbTelemetryConfig config2; |
| 63 | |
| 64 | @Before |
| 65 | public void setup() { |
| 66 | |
| 67 | InfluxDbTelemetryConfig.Builder builder1 = |
| 68 | new DefaultInfluxDbTelemetryConfig.DefaultBuilder(); |
| 69 | InfluxDbTelemetryConfig.Builder builder2 = |
| 70 | new DefaultInfluxDbTelemetryConfig.DefaultBuilder(); |
| 71 | InfluxDbTelemetryConfig.Builder builder3 = |
| 72 | new DefaultInfluxDbTelemetryConfig.DefaultBuilder(); |
| 73 | |
| 74 | config1 = builder1 |
| 75 | .withAddress(IP_ADDRESS_1) |
| 76 | .withPort(PORT_1) |
| 77 | .withDatabase(DATABASE_1) |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame^] | 78 | .withMeasurement(MEASUREMENT_1) |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 79 | .withUsername(USERNAME_1) |
| 80 | .withPassword(PASSWORD_1) |
| 81 | .withEnableBatch(ENABLE_BATCH_1) |
| 82 | .withConfigMap(CONFIG_MAP_1) |
| 83 | .build(); |
| 84 | |
| 85 | sameAsConfig1 = builder2 |
| 86 | .withAddress(IP_ADDRESS_1) |
| 87 | .withPort(PORT_1) |
| 88 | .withDatabase(DATABASE_1) |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame^] | 89 | .withMeasurement(MEASUREMENT_1) |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 90 | .withUsername(USERNAME_1) |
| 91 | .withPassword(PASSWORD_1) |
| 92 | .withEnableBatch(ENABLE_BATCH_1) |
| 93 | .withConfigMap(CONFIG_MAP_1) |
| 94 | .build(); |
| 95 | |
| 96 | config2 = builder3 |
| 97 | .withAddress(IP_ADDRESS_2) |
| 98 | .withPort(PORT_2) |
| 99 | .withDatabase(DATABASE_2) |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame^] | 100 | .withMeasurement(MEASUREMENT_2) |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 101 | .withUsername(USERNAME_2) |
| 102 | .withPassword(PASSWORD_2) |
| 103 | .withEnableBatch(ENABLE_BATCH_2) |
| 104 | .withConfigMap(CONFIG_MAP_2) |
| 105 | .build(); |
| 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testEquality() { |
| 110 | new EqualsTester() |
| 111 | .addEqualityGroup(config1, sameAsConfig1) |
| 112 | .addEqualityGroup(config2).testEquals(); |
| 113 | } |
| 114 | |
| 115 | @Test |
| 116 | public void testConstruction() { |
| 117 | InfluxDbTelemetryConfig config = config1; |
| 118 | |
| 119 | assertThat(config.address(), is(IP_ADDRESS_1)); |
| 120 | assertThat(config.port(), is(PORT_1)); |
| 121 | assertThat(config.database(), is(DATABASE_1)); |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame^] | 122 | assertThat(config.measurement(), is(MEASUREMENT_1)); |
Jian Li | 52c1122 | 2018-06-07 11:39:17 +0900 | [diff] [blame] | 123 | assertThat(config.username(), is(USERNAME_1)); |
| 124 | assertThat(config.password(), is(PASSWORD_1)); |
| 125 | assertThat(config.enableBatch(), is(ENABLE_BATCH_1)); |
| 126 | assertThat(config.configMap(), is(CONFIG_MAP_1)); |
| 127 | } |
| 128 | } |