blob: 6dcf22938e17cd9f8debdcfcc51dbcea4ab6a0c3 [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.GrpcTelemetryConfig;
23
24import java.util.Map;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28
29/**
30 * Unit tests for DefaultGrpcTelemetryConfig class.
31 */
Jian Li3db90852018-06-10 22:29:16 +090032public final class DefaultGrpcTelemetryConfigTest {
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 int MSG_SIZE_1 = 1000;
41 private static final int MSG_SIZE_2 = 2000;
42
43 private static final boolean USE_PLAIN_TEXT_1 = true;
44 private static final boolean USE_PLAIN_TEXT_2 = true;
45
46 private static final Map<String, Object> CONFIG_MAP_1 =
47 ImmutableMap.of("key1", "value1");
48 private static final Map<String, Object> CONFIG_MAP_2 =
49 ImmutableMap.of("key2", "value2");
50
51 private GrpcTelemetryConfig config1;
52 private GrpcTelemetryConfig sameAsConfig1;
53 private GrpcTelemetryConfig config2;
54
55 @Before
56 public void setup() {
57
58 GrpcTelemetryConfig.Builder builder1 =
59 new DefaultGrpcTelemetryConfig.DefaultBuilder();
60 GrpcTelemetryConfig.Builder builder2 =
61 new DefaultGrpcTelemetryConfig.DefaultBuilder();
62 GrpcTelemetryConfig.Builder builder3 =
63 new DefaultGrpcTelemetryConfig.DefaultBuilder();
64
65 config1 = builder1
66 .withAddress(IP_ADDRESS_1)
67 .withPort(PORT_1)
68 .withMaxInboundMsgSize(MSG_SIZE_1)
69 .withUsePlaintext(USE_PLAIN_TEXT_1)
70 .withConfigMap(CONFIG_MAP_1)
71 .build();
72
73 sameAsConfig1 = builder2
74 .withAddress(IP_ADDRESS_1)
75 .withPort(PORT_1)
76 .withMaxInboundMsgSize(MSG_SIZE_1)
77 .withUsePlaintext(USE_PLAIN_TEXT_1)
78 .withConfigMap(CONFIG_MAP_1)
79 .build();
80
81 config2 = builder3
82 .withAddress(IP_ADDRESS_2)
83 .withPort(PORT_2)
84 .withMaxInboundMsgSize(MSG_SIZE_2)
85 .withUsePlaintext(USE_PLAIN_TEXT_2)
86 .withConfigMap(CONFIG_MAP_2)
87 .build();
88 }
89
90 @Test
91 public void testEquality() {
92 new EqualsTester()
93 .addEqualityGroup(config1, sameAsConfig1)
94 .addEqualityGroup(config2).testEquals();
95 }
96
97 @Test
98 public void testConstruction() {
99 GrpcTelemetryConfig config = config1;
100
101 assertThat(config.address(), is(IP_ADDRESS_1));
102 assertThat(config.port(), is(PORT_1));
103 assertThat(config.maxInboundMsgSize(), is(MSG_SIZE_1));
104 assertThat(config.usePlaintext(), is(USE_PLAIN_TEXT_1));
105 assertThat(config.configMap(), is(CONFIG_MAP_1));
106 }
107}