blob: 2357fecc32a2ad2e8a8d6d952f0e6b99c3c9afc8 [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;
Jian Liae3fcff2018-07-30 11:55:44 +090028import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Jian Li52c11222018-06-07 11:39:17 +090029
30/**
31 * Unit tests for DefaultInfluxDbTelemetryConfig class.
32 */
Jian Li3db90852018-06-10 22:29:16 +090033public final class DefaultInfluxDbTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090034
35 private static final String IP_ADDRESS_1 = "10.10.10.1";
36 private static final String IP_ADDRESS_2 = "20.20.20.1";
37
38 private static final int PORT_1 = 80;
39 private static final int PORT_2 = 8080;
40
41 private static final String DATABASE_1 = "database1";
42 private static final String DATABASE_2 = "database2";
43
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090044 private static final String MEASUREMENT_1 = "measurement1";
45 private static final String MEASUREMENT_2 = "measurement2";
46
Jian Li52c11222018-06-07 11:39:17 +090047 private static final String USERNAME_1 = "username1";
48 private static final String USERNAME_2 = "username2";
49
50 private static final String PASSWORD_1 = "password1";
51 private static final String PASSWORD_2 = "password2";
52
53 private static final boolean ENABLE_BATCH_1 = true;
54 private static final boolean ENABLE_BATCH_2 = false;
55
56 private static final Map<String, Object> CONFIG_MAP_1 =
57 ImmutableMap.of("key1", "value1");
58 private static final Map<String, Object> CONFIG_MAP_2 =
59 ImmutableMap.of("key2", "value2");
60
61 private InfluxDbTelemetryConfig config1;
62 private InfluxDbTelemetryConfig sameAsConfig1;
63 private InfluxDbTelemetryConfig config2;
64
Jian Liae3fcff2018-07-30 11:55:44 +090065 /**
66 * Initial setup for this unit test.
67 */
Jian Li52c11222018-06-07 11:39:17 +090068 @Before
69 public void setup() {
70
71 InfluxDbTelemetryConfig.Builder builder1 =
72 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
73 InfluxDbTelemetryConfig.Builder builder2 =
74 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
75 InfluxDbTelemetryConfig.Builder builder3 =
76 new DefaultInfluxDbTelemetryConfig.DefaultBuilder();
77
78 config1 = builder1
79 .withAddress(IP_ADDRESS_1)
80 .withPort(PORT_1)
81 .withDatabase(DATABASE_1)
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090082 .withMeasurement(MEASUREMENT_1)
Jian Li52c11222018-06-07 11:39:17 +090083 .withUsername(USERNAME_1)
84 .withPassword(PASSWORD_1)
85 .withEnableBatch(ENABLE_BATCH_1)
86 .withConfigMap(CONFIG_MAP_1)
87 .build();
88
89 sameAsConfig1 = builder2
90 .withAddress(IP_ADDRESS_1)
91 .withPort(PORT_1)
92 .withDatabase(DATABASE_1)
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090093 .withMeasurement(MEASUREMENT_1)
Jian Li52c11222018-06-07 11:39:17 +090094 .withUsername(USERNAME_1)
95 .withPassword(PASSWORD_1)
96 .withEnableBatch(ENABLE_BATCH_1)
97 .withConfigMap(CONFIG_MAP_1)
98 .build();
99
100 config2 = builder3
101 .withAddress(IP_ADDRESS_2)
102 .withPort(PORT_2)
103 .withDatabase(DATABASE_2)
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +0900104 .withMeasurement(MEASUREMENT_2)
Jian Li52c11222018-06-07 11:39:17 +0900105 .withUsername(USERNAME_2)
106 .withPassword(PASSWORD_2)
107 .withEnableBatch(ENABLE_BATCH_2)
108 .withConfigMap(CONFIG_MAP_2)
109 .build();
110 }
111
Jian Liae3fcff2018-07-30 11:55:44 +0900112 /**
113 * Tests class immutability.
114 */
115 @Test
116 public void testImmutability() {
117 assertThatClassIsImmutable(DefaultInfluxDbTelemetryConfig.class);
118 }
119
120 /**
121 * Tests object equality.
122 */
Jian Li52c11222018-06-07 11:39:17 +0900123 @Test
124 public void testEquality() {
125 new EqualsTester()
126 .addEqualityGroup(config1, sameAsConfig1)
127 .addEqualityGroup(config2).testEquals();
128 }
129
Jian Liae3fcff2018-07-30 11:55:44 +0900130 /**
131 * Tests object construction.
132 */
Jian Li52c11222018-06-07 11:39:17 +0900133 @Test
134 public void testConstruction() {
135 InfluxDbTelemetryConfig config = config1;
136
137 assertThat(config.address(), is(IP_ADDRESS_1));
138 assertThat(config.port(), is(PORT_1));
139 assertThat(config.database(), is(DATABASE_1));
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +0900140 assertThat(config.measurement(), is(MEASUREMENT_1));
Jian Li52c11222018-06-07 11:39:17 +0900141 assertThat(config.username(), is(USERNAME_1));
142 assertThat(config.password(), is(PASSWORD_1));
143 assertThat(config.enableBatch(), is(ENABLE_BATCH_1));
144 assertThat(config.configMap(), is(CONFIG_MAP_1));
145 }
146}