blob: 4af5b4ab8b566e64027f5841ed214a5166efb5a5 [file] [log] [blame]
Jian Li52c11222018-06-07 11:39:17 +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.InfluxDbTelemetryConfig;
23
24import java.util.Map;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28
29/**
30 * Unit tests for DefaultInfluxDbTelemetryConfig class.
31 */
Jian Li3db90852018-06-10 22:29:16 +090032public final class DefaultInfluxDbTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090033
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 Jeong4d1c9d12018-07-20 17:09:20 +090043 private static final String MEASUREMENT_1 = "measurement1";
44 private static final String MEASUREMENT_2 = "measurement2";
45
Jian Li52c11222018-06-07 11:39:17 +090046 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 Jeong4d1c9d12018-07-20 17:09:20 +090078 .withMeasurement(MEASUREMENT_1)
Jian Li52c11222018-06-07 11:39:17 +090079 .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 Jeong4d1c9d12018-07-20 17:09:20 +090089 .withMeasurement(MEASUREMENT_1)
Jian Li52c11222018-06-07 11:39:17 +090090 .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 Jeong4d1c9d12018-07-20 17:09:20 +0900100 .withMeasurement(MEASUREMENT_2)
Jian Li52c11222018-06-07 11:39:17 +0900101 .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 Jeong4d1c9d12018-07-20 17:09:20 +0900122 assertThat(config.measurement(), is(MEASUREMENT_1));
Jian Li52c11222018-06-07 11:39:17 +0900123 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}