blob: 2a6277b859a9e39e9bcaad6e7fa547f34a95c8c8 [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;
28
Jian Li3db90852018-06-10 22:29:16 +090029public final class DefaultRestTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090030
31 private static final String IP_ADDRESS_1 = "10.10.10.1";
32 private static final String IP_ADDRESS_2 = "20.20.20.1";
33
34 private static final int PORT_1 = 80;
35 private static final int PORT_2 = 8080;
36
37 private static final String ENDPOINT_1 = "telemetry";
38 private static final String ENDPOINT_2 = "configuration";
39
40 private static final String METHOD_1 = "POST";
41 private static final String METHOD_2 = "GET";
42
43 private static final String REQUEST_MEDIA_TYPE_1 = "JSON";
44 private static final String REQUEST_MEDIA_TYPE_2 = "XML";
45
46 private static final String RESPONSE_MEDIA_TYPE_1 = "JSON";
47 private static final String RESPONSE_MEDIA_TYPE_2 = "XML";
48
49 private static final Map<String, Object> CONFIG_MAP_1 =
50 ImmutableMap.of("key1", "value1");
51 private static final Map<String, Object> CONFIG_MAP_2 =
52 ImmutableMap.of("key2", "value2");
53
54 private RestTelemetryConfig config1;
55 private RestTelemetryConfig sameAsConfig1;
56 private RestTelemetryConfig config2;
57
58 @Before
59 public void setup() {
60
61 RestTelemetryConfig.Builder builder1 =
62 new DefaultRestTelemetryConfig.DefaultBuilder();
63 RestTelemetryConfig.Builder builder2 =
64 new DefaultRestTelemetryConfig.DefaultBuilder();
65 RestTelemetryConfig.Builder builder3 =
66 new DefaultRestTelemetryConfig.DefaultBuilder();
67
68 config1 = builder1
69 .withAddress(IP_ADDRESS_1)
70 .withPort(PORT_1)
71 .withEndpoint(ENDPOINT_1)
72 .withMethod(METHOD_1)
73 .withRequestMediaType(REQUEST_MEDIA_TYPE_1)
74 .withResponseMediaType(RESPONSE_MEDIA_TYPE_1)
75 .withConfigMap(CONFIG_MAP_1)
76 .build();
77
78 sameAsConfig1 = builder2
79 .withAddress(IP_ADDRESS_1)
80 .withPort(PORT_1)
81 .withEndpoint(ENDPOINT_1)
82 .withMethod(METHOD_1)
83 .withRequestMediaType(REQUEST_MEDIA_TYPE_1)
84 .withResponseMediaType(RESPONSE_MEDIA_TYPE_1)
85 .withConfigMap(CONFIG_MAP_1)
86 .build();
87
88 config2 = builder3
89 .withAddress(IP_ADDRESS_2)
90 .withPort(PORT_2)
91 .withEndpoint(ENDPOINT_2)
92 .withMethod(METHOD_2)
93 .withRequestMediaType(REQUEST_MEDIA_TYPE_2)
94 .withResponseMediaType(RESPONSE_MEDIA_TYPE_2)
95 .withConfigMap(CONFIG_MAP_2)
96 .build();
97 }
98
99 @Test
100 public void testEquality() {
101 new EqualsTester()
102 .addEqualityGroup(config1, sameAsConfig1)
103 .addEqualityGroup(config2).testEquals();
104 }
105
106 @Test
107 public void testConstruction() {
108 RestTelemetryConfig config = config1;
109
110 assertThat(config.address(), is(IP_ADDRESS_1));
111 assertThat(config.port(), is(PORT_1));
112 assertThat(config.endpoint(), is(ENDPOINT_1));
113 assertThat(config.method(), is(METHOD_1));
114 assertThat(config.requestMediaType(), is(REQUEST_MEDIA_TYPE_1));
115 assertThat(config.responseMediaType(), is(RESPONSE_MEDIA_TYPE_1));
116 assertThat(config.configMap(), is(CONFIG_MAP_1));
117 }
118}