blob: 3c95f6d1d70b98abd0923ee4a46363f308e7f41e [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
43 private static final String USERNAME_1 = "username1";
44 private static final String USERNAME_2 = "username2";
45
46 private static final String PASSWORD_1 = "password1";
47 private static final String PASSWORD_2 = "password2";
48
49 private static final boolean ENABLE_BATCH_1 = true;
50 private static final boolean ENABLE_BATCH_2 = false;
51
52 private static final Map<String, Object> CONFIG_MAP_1 =
53 ImmutableMap.of("key1", "value1");
54 private static final Map<String, Object> CONFIG_MAP_2 =
55 ImmutableMap.of("key2", "value2");
56
57 private InfluxDbTelemetryConfig config1;
58 private InfluxDbTelemetryConfig sameAsConfig1;
59 private InfluxDbTelemetryConfig config2;
60
61 @Before
62 public void setup() {
63
64 InfluxDbTelemetryConfig.Builder builder1 =
65 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
66 InfluxDbTelemetryConfig.Builder builder2 =
67 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
68 InfluxDbTelemetryConfig.Builder builder3 =
69 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
70
71 config1 = builder1
72 .withAddress(IP_ADDRESS_1)
73 .withPort(PORT_1)
74 .withDatabase(DATABASE_1)
75 .withUsername(USERNAME_1)
76 .withPassword(PASSWORD_1)
77 .withEnableBatch(ENABLE_BATCH_1)
78 .withConfigMap(CONFIG_MAP_1)
79 .build();
80
81 sameAsConfig1 = builder2
82 .withAddress(IP_ADDRESS_1)
83 .withPort(PORT_1)
84 .withDatabase(DATABASE_1)
85 .withUsername(USERNAME_1)
86 .withPassword(PASSWORD_1)
87 .withEnableBatch(ENABLE_BATCH_1)
88 .withConfigMap(CONFIG_MAP_1)
89 .build();
90
91 config2 = builder3
92 .withAddress(IP_ADDRESS_2)
93 .withPort(PORT_2)
94 .withDatabase(DATABASE_2)
95 .withUsername(USERNAME_2)
96 .withPassword(PASSWORD_2)
97 .withEnableBatch(ENABLE_BATCH_2)
98 .withConfigMap(CONFIG_MAP_2)
99 .build();
100 }
101
102 @Test
103 public void testEquality() {
104 new EqualsTester()
105 .addEqualityGroup(config1, sameAsConfig1)
106 .addEqualityGroup(config2).testEquals();
107 }
108
109 @Test
110 public void testConstruction() {
111 InfluxDbTelemetryConfig config = config1;
112
113 assertThat(config.address(), is(IP_ADDRESS_1));
114 assertThat(config.port(), is(PORT_1));
115 assertThat(config.database(), is(DATABASE_1));
116 assertThat(config.username(), is(USERNAME_1));
117 assertThat(config.password(), is(PASSWORD_1));
118 assertThat(config.enableBatch(), is(ENABLE_BATCH_1));
119 assertThat(config.configMap(), is(CONFIG_MAP_1));
120 }
121}