blob: 3e8bac06223636cc0f246ee3e68b44a58a31d579 [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.RestTelemetryConfig;
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
Jian Li3db90852018-06-10 22:29:16 +090030public final class DefaultRestTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090031
32 private static final String IP_ADDRESS_1 = "10.10.10.1";
33 private static final String IP_ADDRESS_2 = "20.20.20.1";
34
35 private static final int PORT_1 = 80;
36 private static final int PORT_2 = 8080;
37
38 private static final String ENDPOINT_1 = "telemetry";
39 private static final String ENDPOINT_2 = "configuration";
40
41 private static final String METHOD_1 = "POST";
42 private static final String METHOD_2 = "GET";
43
44 private static final String REQUEST_MEDIA_TYPE_1 = "JSON";
45 private static final String REQUEST_MEDIA_TYPE_2 = "XML";
46
47 private static final String RESPONSE_MEDIA_TYPE_1 = "JSON";
48 private static final String RESPONSE_MEDIA_TYPE_2 = "XML";
49
50 private static final Map<String, Object> CONFIG_MAP_1 =
51 ImmutableMap.of("key1", "value1");
52 private static final Map<String, Object> CONFIG_MAP_2 =
53 ImmutableMap.of("key2", "value2");
54
55 private RestTelemetryConfig config1;
56 private RestTelemetryConfig sameAsConfig1;
57 private RestTelemetryConfig config2;
58
Jian Liae3fcff2018-07-30 11:55:44 +090059 /**
60 * Initial setup for this unit test.
61 */
Jian Li52c11222018-06-07 11:39:17 +090062 @Before
63 public void setup() {
64
65 RestTelemetryConfig.Builder builder1 =
66 new DefaultRestTelemetryConfig.DefaultBuilder();
67 RestTelemetryConfig.Builder builder2 =
68 new DefaultRestTelemetryConfig.DefaultBuilder();
69 RestTelemetryConfig.Builder builder3 =
70 new DefaultRestTelemetryConfig.DefaultBuilder();
71
72 config1 = builder1
73 .withAddress(IP_ADDRESS_1)
74 .withPort(PORT_1)
75 .withEndpoint(ENDPOINT_1)
76 .withMethod(METHOD_1)
77 .withRequestMediaType(REQUEST_MEDIA_TYPE_1)
78 .withResponseMediaType(RESPONSE_MEDIA_TYPE_1)
79 .withConfigMap(CONFIG_MAP_1)
80 .build();
81
82 sameAsConfig1 = builder2
83 .withAddress(IP_ADDRESS_1)
84 .withPort(PORT_1)
85 .withEndpoint(ENDPOINT_1)
86 .withMethod(METHOD_1)
87 .withRequestMediaType(REQUEST_MEDIA_TYPE_1)
88 .withResponseMediaType(RESPONSE_MEDIA_TYPE_1)
89 .withConfigMap(CONFIG_MAP_1)
90 .build();
91
92 config2 = builder3
93 .withAddress(IP_ADDRESS_2)
94 .withPort(PORT_2)
95 .withEndpoint(ENDPOINT_2)
96 .withMethod(METHOD_2)
97 .withRequestMediaType(REQUEST_MEDIA_TYPE_2)
98 .withResponseMediaType(RESPONSE_MEDIA_TYPE_2)
99 .withConfigMap(CONFIG_MAP_2)
100 .build();
101 }
102
Jian Liae3fcff2018-07-30 11:55:44 +0900103 /**
104 * Tests class immutability.
105 */
106 @Test
107 public void testImmutability() {
108 assertThatClassIsImmutable(DefaultRestTelemetryConfig.class);
109 }
110
111 /**
112 * Tests object equality.
113 */
Jian Li52c11222018-06-07 11:39:17 +0900114 @Test
115 public void testEquality() {
116 new EqualsTester()
117 .addEqualityGroup(config1, sameAsConfig1)
118 .addEqualityGroup(config2).testEquals();
119 }
120
Jian Liae3fcff2018-07-30 11:55:44 +0900121 /**
122 * Tests object construction.
123 */
Jian Li52c11222018-06-07 11:39:17 +0900124 @Test
125 public void testConstruction() {
126 RestTelemetryConfig config = config1;
127
128 assertThat(config.address(), is(IP_ADDRESS_1));
129 assertThat(config.port(), is(PORT_1));
130 assertThat(config.endpoint(), is(ENDPOINT_1));
131 assertThat(config.method(), is(METHOD_1));
132 assertThat(config.requestMediaType(), is(REQUEST_MEDIA_TYPE_1));
133 assertThat(config.responseMediaType(), is(RESPONSE_MEDIA_TYPE_1));
134 assertThat(config.configMap(), is(CONFIG_MAP_1));
135 }
136}