Skip to content

Commit 45f07f9

Browse files
authored
unit test for RegistryConfigTest (apache#1775)
1 parent 23070d8 commit 45f07f9

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.alibaba.dubbo.config;
19+
20+
import com.alibaba.dubbo.common.Constants;
21+
import org.junit.Test;
22+
23+
import java.util.Collections;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
import static org.hamcrest.CoreMatchers.is;
28+
import static org.hamcrest.Matchers.equalTo;
29+
import static org.hamcrest.Matchers.hasEntry;
30+
import static org.hamcrest.Matchers.hasKey;
31+
import static org.hamcrest.Matchers.not;
32+
import static org.junit.Assert.assertThat;
33+
34+
public class RegistryConfigTest {
35+
@Test
36+
public void testProtocol() throws Exception {
37+
RegistryConfig registry = new RegistryConfig();
38+
registry.setProtocol("protocol");
39+
assertThat(registry.getProtocol(), equalTo(registry.getProtocol()));
40+
}
41+
42+
@Test
43+
public void testAddress() throws Exception {
44+
RegistryConfig registry = new RegistryConfig();
45+
registry.setAddress("localhost");
46+
assertThat(registry.getAddress(), equalTo("localhost"));
47+
Map<String, String> parameters = new HashMap<String, String>();
48+
RegistryConfig.appendParameters(parameters, registry);
49+
assertThat(parameters, not(hasKey("address")));
50+
}
51+
52+
@Test
53+
public void testUsername() throws Exception {
54+
RegistryConfig registry = new RegistryConfig();
55+
registry.setUsername("username");
56+
assertThat(registry.getUsername(), equalTo("username"));
57+
}
58+
59+
@Test
60+
public void testPassword() throws Exception {
61+
RegistryConfig registry = new RegistryConfig();
62+
registry.setPassword("password");
63+
assertThat(registry.getPassword(), equalTo("password"));
64+
}
65+
66+
@Test
67+
public void testWait() throws Exception {
68+
RegistryConfig registry = new RegistryConfig();
69+
registry.setWait(10);
70+
assertThat(registry.getWait(), is(10));
71+
assertThat(System.getProperty(Constants.SHUTDOWN_WAIT_KEY), equalTo("10"));
72+
}
73+
74+
@Test
75+
public void testCheck() throws Exception {
76+
RegistryConfig registry = new RegistryConfig();
77+
registry.setCheck(true);
78+
assertThat(registry.isCheck(), is(true));
79+
}
80+
81+
@Test
82+
public void testFile() throws Exception {
83+
RegistryConfig registry = new RegistryConfig();
84+
registry.setFile("file");
85+
assertThat(registry.getFile(), equalTo("file"));
86+
}
87+
88+
@Test
89+
public void testTransporter() throws Exception {
90+
RegistryConfig registry = new RegistryConfig();
91+
registry.setTransporter("transporter");
92+
assertThat(registry.getTransporter(), equalTo("transporter"));
93+
}
94+
95+
@Test
96+
public void testClient() throws Exception {
97+
RegistryConfig registry = new RegistryConfig();
98+
registry.setClient("client");
99+
assertThat(registry.getClient(), equalTo("client"));
100+
}
101+
102+
@Test
103+
public void testTimeout() throws Exception {
104+
RegistryConfig registry = new RegistryConfig();
105+
registry.setTimeout(10);
106+
assertThat(registry.getTimeout(), is(10));
107+
}
108+
109+
@Test
110+
public void testSession() throws Exception {
111+
RegistryConfig registry = new RegistryConfig();
112+
registry.setSession(10);
113+
assertThat(registry.getSession(), is(10));
114+
}
115+
116+
@Test
117+
public void testDynamic() throws Exception {
118+
RegistryConfig registry = new RegistryConfig();
119+
registry.setDynamic(true);
120+
assertThat(registry.isDynamic(), is(true));
121+
}
122+
123+
@Test
124+
public void testRegister() throws Exception {
125+
RegistryConfig registry = new RegistryConfig();
126+
registry.setRegister(true);
127+
assertThat(registry.isRegister(), is(true));
128+
}
129+
130+
@Test
131+
public void testSubscribe() throws Exception {
132+
RegistryConfig registry = new RegistryConfig();
133+
registry.setSubscribe(true);
134+
assertThat(registry.isSubscribe(), is(true));
135+
}
136+
137+
@Test
138+
public void testCluster() throws Exception {
139+
RegistryConfig registry = new RegistryConfig();
140+
registry.setCluster("cluster");
141+
assertThat(registry.getCluster(), equalTo("cluster"));
142+
}
143+
144+
@Test
145+
public void testGroup() throws Exception {
146+
RegistryConfig registry = new RegistryConfig();
147+
registry.setGroup("group");
148+
assertThat(registry.getGroup(), equalTo("group"));
149+
}
150+
151+
@Test
152+
public void testVersion() throws Exception {
153+
RegistryConfig registry = new RegistryConfig();
154+
registry.setVersion("1.0.0");
155+
assertThat(registry.getVersion(), equalTo("1.0.0"));
156+
}
157+
158+
@Test
159+
public void testParameters() throws Exception {
160+
RegistryConfig registry = new RegistryConfig();
161+
registry.setParameters(Collections.singletonMap("k1", "v1"));
162+
assertThat(registry.getParameters(), hasEntry("k1", "v1"));
163+
Map<String, String> parameters = new HashMap<String, String>();
164+
RegistryConfig.appendParameters(parameters, registry);
165+
assertThat(parameters, hasEntry("k1", "v1"));
166+
}
167+
168+
@Test
169+
public void testDefault() throws Exception {
170+
RegistryConfig registry = new RegistryConfig();
171+
registry.setDefault(true);
172+
assertThat(registry.isDefault(), is(true));
173+
}
174+
}

0 commit comments

Comments
 (0)