blob: 6734cfa7852d019bbfc111c310179e83beda41c4 [file] [log] [blame]
Jian Li69600e02018-12-24 13:21:18 +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 */
Jian Li7fe7eaf2018-12-31 17:00:33 +090016package org.onosproject.openstacktelemetry.api;
Jian Li69600e02018-12-24 13:21:18 +090017
18import com.google.common.collect.Maps;
19import com.google.common.testing.EqualsTester;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
23import org.onosproject.openstacktelemetry.api.config.TelemetryConfig.ConfigType;
24
25import java.util.Map;
26
27import static org.junit.Assert.assertEquals;
28import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
29
30/**
31 * Unit tests for DefaultTelemetryConfig class.
32 */
33public final class DefaultTelemetryConfigTest {
34
35 private static final String NAME_1 = "grpc";
36 private static final String NAME_2 = "kafka";
37
38 private static final ConfigType TYPE_1 = ConfigType.GRPC;
39 private static final ConfigType TYPE_2 = ConfigType.KAFKA;
40
41 private static final String MANUFACTURER_1 = "grpc.io";
42 private static final String MANUFACTURER_2 = "kafka.apache.org";
43
44 private static final String SW_VERSION_1 = "1.0";
45 private static final String SW_VERSION_2 = "1.0";
46
47 private static final Map<String, String> PROP_1 = Maps.newConcurrentMap();
48 private static final Map<String, String> PROP_2 = Maps.newConcurrentMap();
49
50 private static final String PROP_1_KEY_1 = "key11";
51 private static final String PROP_1_KEY_2 = "key12";
52 private static final String PROP_1_VALUE_1 = "value11";
53 private static final String PROP_1_VALUE_2 = "value12";
54 private static final String PROP_2_KEY_1 = "key21";
55 private static final String PROP_2_KEY_2 = "key22";
56 private static final String PROP_2_VALUE_1 = "value21";
57 private static final String PROP_2_VALUE_2 = "value22";
58
59 private static final boolean ENABLED_1 = true;
60 private static final boolean ENABLED_2 = false;
61
62 private TelemetryConfig config1;
63 private TelemetryConfig sameAsConfig1;
64 private TelemetryConfig config2;
65
66 /**
67 * Initial setup for this unit test.
68 */
69 @Before
70 public void setup() {
71 PROP_1.put(PROP_1_KEY_1, PROP_1_VALUE_1);
72 PROP_1.put(PROP_1_KEY_2, PROP_1_VALUE_2);
73 PROP_2.put(PROP_2_KEY_1, PROP_2_VALUE_1);
74 PROP_2.put(PROP_2_KEY_2, PROP_2_VALUE_2);
75
76 config1 = new DefaultTelemetryConfig(NAME_1, TYPE_1, null,
77 MANUFACTURER_1, SW_VERSION_1, ENABLED_1, PROP_1);
78 sameAsConfig1 = new DefaultTelemetryConfig(NAME_1, TYPE_1, null,
79 MANUFACTURER_1, SW_VERSION_1, ENABLED_1, PROP_1);
80 config2 = new DefaultTelemetryConfig(NAME_2, TYPE_2, null,
81 MANUFACTURER_2, SW_VERSION_2, ENABLED_2, PROP_2);
82 }
83
84 /**
85 * Tests class immutability.
86 */
87 @Test
88 public void testImmutability() {
89 assertThatClassIsImmutable(DefaultTelemetryConfig.class);
90 }
91
92 /**
93 * Tests object equality.
94 */
95 @Test
96 public void testEquality() {
97 new EqualsTester()
98 .addEqualityGroup(config1, sameAsConfig1)
99 .addEqualityGroup(config2).testEquals();
100 }
101
102 /**
103 * Tests object construction.
104 */
105 @Test
106 public void testConstruction() {
107 TelemetryConfig config = config1;
108
109 assertEquals(config.name(), NAME_1);
110 assertEquals(config.type(), TYPE_1);
111 assertEquals(config.manufacturer(), MANUFACTURER_1);
112 assertEquals(config.swVersion(), SW_VERSION_1);
113 assertEquals(config.properties(), PROP_1);
114 assertEquals(config.enabled(), ENABLED_1);
115 }
116}