blob: 1a7f752c6f2735623b9ab1788baebd8271970797 [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;
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 DefaultGrpcTelemetryConfig class.
32 */
Jian Li3db90852018-06-10 22:29:16 +090033public final class DefaultGrpcTelemetryConfigTest {
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 int MSG_SIZE_1 = 1000;
42 private static final int MSG_SIZE_2 = 2000;
43
44 private static final boolean USE_PLAIN_TEXT_1 = true;
45 private static final boolean USE_PLAIN_TEXT_2 = true;
46
47 private static final Map<String, Object> CONFIG_MAP_1 =
48 ImmutableMap.of("key1", "value1");
49 private static final Map<String, Object> CONFIG_MAP_2 =
50 ImmutableMap.of("key2", "value2");
51
52 private GrpcTelemetryConfig config1;
53 private GrpcTelemetryConfig sameAsConfig1;
54 private GrpcTelemetryConfig config2;
55
Jian Liae3fcff2018-07-30 11:55:44 +090056 /**
57 * Initial setup for this unit test.
58 */
Jian Li52c11222018-06-07 11:39:17 +090059 @Before
60 public void setup() {
61
62 GrpcTelemetryConfig.Builder builder1 =
63 new DefaultGrpcTelemetryConfig.DefaultBuilder();
64 GrpcTelemetryConfig.Builder builder2 =
65 new DefaultGrpcTelemetryConfig.DefaultBuilder();
66 GrpcTelemetryConfig.Builder builder3 =
67 new DefaultGrpcTelemetryConfig.DefaultBuilder();
68
69 config1 = builder1
70 .withAddress(IP_ADDRESS_1)
71 .withPort(PORT_1)
72 .withMaxInboundMsgSize(MSG_SIZE_1)
73 .withUsePlaintext(USE_PLAIN_TEXT_1)
74 .withConfigMap(CONFIG_MAP_1)
75 .build();
76
77 sameAsConfig1 = builder2
78 .withAddress(IP_ADDRESS_1)
79 .withPort(PORT_1)
80 .withMaxInboundMsgSize(MSG_SIZE_1)
81 .withUsePlaintext(USE_PLAIN_TEXT_1)
82 .withConfigMap(CONFIG_MAP_1)
83 .build();
84
85 config2 = builder3
86 .withAddress(IP_ADDRESS_2)
87 .withPort(PORT_2)
88 .withMaxInboundMsgSize(MSG_SIZE_2)
89 .withUsePlaintext(USE_PLAIN_TEXT_2)
90 .withConfigMap(CONFIG_MAP_2)
91 .build();
92 }
93
Jian Liae3fcff2018-07-30 11:55:44 +090094 /**
95 * Tests class immutability.
96 */
97 @Test
98 public void testImmutability() {
99 assertThatClassIsImmutable(DefaultGrpcTelemetryConfig.class);
100 }
101
102 /**
103 * Tests object equality.
104 */
Jian Li52c11222018-06-07 11:39:17 +0900105 @Test
106 public void testEquality() {
107 new EqualsTester()
108 .addEqualityGroup(config1, sameAsConfig1)
109 .addEqualityGroup(config2).testEquals();
110 }
111
Jian Liae3fcff2018-07-30 11:55:44 +0900112 /**
113 * Tests object construction.
114 */
Jian Li52c11222018-06-07 11:39:17 +0900115 @Test
116 public void testConstruction() {
117 GrpcTelemetryConfig config = config1;
118
119 assertThat(config.address(), is(IP_ADDRESS_1));
120 assertThat(config.port(), is(PORT_1));
121 assertThat(config.maxInboundMsgSize(), is(MSG_SIZE_1));
122 assertThat(config.usePlaintext(), is(USE_PLAIN_TEXT_1));
123 assertThat(config.configMap(), is(CONFIG_MAP_1));
124 }
125}