From ca8883924466f0d3eeeac6b19e42ad228d6ae8ae Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Wed, 9 May 2018 17:53:16 +0800 Subject: [PATCH] Config api unit test (#1758) * unit test for ApplicationConfig * fix typo * unit test for ArgumentConfig * unit test for ConsumerConfig * unit test for MethodConfig * unit test for ModuleConfig * unit test for MonitorConfig * unit test for ProtocolConfig * unit test for ApplicationConfig * fix typo * unit test for ArgumentConfig * unit test for ConsumerConfig * unit test for MethodConfig * unit test for ModuleConfig * unit test for MonitorConfig * unit test for ProtocolConfig * unit test for ProviderConfig * make test stable --- .../alibaba/dubbo/config/ArgumentConfig.java | 2 +- .../dubbo/config/ApplicationConfigTest.java | 177 ++++++++++++++ .../dubbo/config/ArgumentConfigTest.java | 63 +++++ .../dubbo/config/ConsumerConfigTest.java | 53 +++++ .../dubbo/config/MethodConfigTest.java | 182 +++++++++++++++ .../com/alibaba/dubbo/config/MockCodec.java | 37 +++ .../alibaba/dubbo/config/MockDispatcher.java | 29 +++ .../alibaba/dubbo/config/MockExchanger.java | 37 +++ .../alibaba/dubbo/config/MockProtocol2.java | 48 ++++ .../dubbo/config/MockStatusChecker.java | 28 +++ .../dubbo/config/MockTelnetHandler.java | 29 +++ .../alibaba/dubbo/config/MockThreadPool.java | 30 +++ .../alibaba/dubbo/config/MockTransporter.java | 37 +++ .../dubbo/config/ModuleConfigTest.java | 110 +++++++++ .../dubbo/config/MonitorConfigTest.java | 107 +++++++++ .../dubbo/config/ProtocolConfigTest.java | 219 ++++++++++++++++++ .../dubbo/config/ProviderConfigTest.java | 219 ++++++++++++++++++ ....alibaba.dubbo.common.status.StatusChecker | 18 ++ ...alibaba.dubbo.common.threadpool.ThreadPool | 18 ++ .../services/com.alibaba.dubbo.remoting.Codec | 18 ++ .../com.alibaba.dubbo.remoting.Dispatcher | 18 ++ .../com.alibaba.dubbo.remoting.Transporter | 18 ++ ....alibaba.dubbo.remoting.exchange.Exchanger | 18 ++ ...libaba.dubbo.remoting.telnet.TelnetHandler | 18 ++ .../services/com.alibaba.dubbo.rpc.Protocol | 3 +- 25 files changed, 1534 insertions(+), 2 deletions(-) create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ApplicationConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ArgumentConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ConsumerConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MethodConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockCodec.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockDispatcher.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockExchanger.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockProtocol2.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockStatusChecker.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTelnetHandler.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockThreadPool.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTransporter.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ModuleConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MonitorConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProtocolConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProviderConfigTest.java create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.status.StatusChecker create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Codec create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Dispatcher create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Transporter create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.exchange.Exchanger create mode 100644 dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.telnet.TelnetHandler diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ArgumentConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ArgumentConfig.java index 61fff8defce..e752726a0ca 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ArgumentConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ArgumentConfig.java @@ -27,7 +27,7 @@ public class ArgumentConfig implements Serializable { private static final long serialVersionUID = -2165482463925213595L; - //arugment index -1 represents not set + //argument: index -1 represents not set private Integer index = -1; //argument type diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ApplicationConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ApplicationConfigTest.java new file mode 100644 index 00000000000..f60bb85698f --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ApplicationConfigTest.java @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.Constants; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.sameInstance; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.junit.Assert.assertThat; + +public class ApplicationConfigTest { + @Test + public void testName() throws Exception { + ApplicationConfig application = new ApplicationConfig(); + application.setName("app"); + assertThat(application.getName(), equalTo("app")); + application = new ApplicationConfig("app2"); + assertThat(application.getName(), equalTo("app2")); + Map parameters = new HashMap(); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry(Constants.APPLICATION_KEY, "app2")); + } + + @Test + public void testVersion() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setVersion("1.0.0"); + assertThat(application.getVersion(), equalTo("1.0.0")); + Map parameters = new HashMap(); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry("application.version", "1.0.0")); + } + + @Test + public void testOwner() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setOwner("owner"); + assertThat(application.getOwner(), equalTo("owner")); + } + + @Test + public void testOrganization() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setOrganization("org"); + assertThat(application.getOrganization(), equalTo("org")); + } + + @Test + public void testArchitecture() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setArchitecture("arch"); + assertThat(application.getArchitecture(), equalTo("arch")); + } + + @Test + public void testEnvironment1() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setEnvironment("develop"); + assertThat(application.getEnvironment(), equalTo("develop")); + application.setEnvironment("test"); + assertThat(application.getEnvironment(), equalTo("test")); + application.setEnvironment("product"); + assertThat(application.getEnvironment(), equalTo("product")); + } + + @Test(expected = IllegalStateException.class) + public void testEnvironment2() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setEnvironment("illegal-env"); + } + + @Test + public void testRegistry() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + RegistryConfig registry = new RegistryConfig(); + application.setRegistry(registry); + assertThat(application.getRegistry(), sameInstance(registry)); + application.setRegistries(Collections.singletonList(registry)); + assertThat(application.getRegistries(), contains(registry)); + assertThat(application.getRegistries(), hasSize(1)); + } + + @Test + public void testMonitor() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setMonitor(new MonitorConfig("monitor-addr")); + assertThat(application.getMonitor().getAddress(), equalTo("monitor-addr")); + application.setMonitor("monitor-addr"); + assertThat(application.getMonitor().getAddress(), equalTo("monitor-addr")); + } + + @Test + public void testLogger() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setLogger("log4j"); + assertThat(application.getLogger(), equalTo("log4j")); + } + + @Test + public void testDefault() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setDefault(true); + assertThat(application.isDefault(), is(true)); + } + + @Test + public void testDumpDirectory() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setDumpDirectory("/dump"); + assertThat(application.getDumpDirectory(), equalTo("/dump")); + Map parameters = new HashMap(); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry(Constants.DUMP_DIRECTORY, "/dump")); + } + + @Test + public void testQosEnable() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setQosEnable(true); + assertThat(application.getQosEnable(), is(true)); + Map parameters = new HashMap(); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry(Constants.QOS_ENABLE, "true")); + } + + @Test + public void testQosPort() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setQosPort(8080); + assertThat(application.getQosPort(), equalTo(8080)); + } + + @Test + public void testQosAcceptForeignIp() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setQosAcceptForeignIp(true); + assertThat(application.getQosAcceptForeignIp(), is(true)); + Map parameters = new HashMap(); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry(Constants.ACCEPT_FOREIGN_IP, "true")); + } + + @Test + public void testParameters() throws Exception { + ApplicationConfig application = new ApplicationConfig("app"); + application.setQosAcceptForeignIp(true); + Map parameters = new HashMap(); + parameters.put("k1", "v1"); + ApplicationConfig.appendParameters(parameters, application); + assertThat(parameters, hasEntry("k1", "v1")); + assertThat(parameters, hasEntry(Constants.ACCEPT_FOREIGN_IP, "true")); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ArgumentConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ArgumentConfigTest.java new file mode 100644 index 00000000000..4e1276f3a51 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ArgumentConfigTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +public class ArgumentConfigTest { + @Test + public void testIndex() throws Exception { + ArgumentConfig argument = new ArgumentConfig(); + argument.setIndex(1); + assertThat(argument.getIndex(), is(1)); + } + + @Test + public void testType() throws Exception { + ArgumentConfig argument = new ArgumentConfig(); + argument.setType("int"); + assertThat(argument.getType(), equalTo("int")); + } + + @Test + public void testCallback() throws Exception { + ArgumentConfig argument = new ArgumentConfig(); + argument.setCallback(true); + assertThat(argument.isCallback(), is(true)); + } + + @Test + public void testArguments() throws Exception { + ArgumentConfig argument = new ArgumentConfig(); + argument.setIndex(1); + argument.setType("int"); + argument.setCallback(true); + Map parameters = new HashMap(); + AbstractServiceConfig.appendParameters(parameters, argument); + assertThat(parameters, hasEntry("callback", "true")); + assertThat(parameters.size(), is(1)); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ConsumerConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ConsumerConfigTest.java new file mode 100644 index 00000000000..4eb2d4979db --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ConsumerConfigTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import org.junit.Test; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +public class ConsumerConfigTest { + @Test + public void testTimeout() throws Exception { + try { + System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + ConsumerConfig consumer = new ConsumerConfig(); + consumer.setTimeout(10); + assertThat(consumer.getTimeout(), is(10)); + assertThat(System.getProperty("sun.rmi.transport.tcp.responseTimeout"), equalTo("10")); + } finally { + System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + } + } + + @Test + public void testDefault() throws Exception { + ConsumerConfig consumer = new ConsumerConfig(); + consumer.setDefault(true); + assertThat(consumer.isDefault(), is(true)); + } + + @Test + public void testClient() throws Exception { + ConsumerConfig consumer = new ConsumerConfig(); + consumer.setClient("client"); + assertThat(consumer.getClient(), equalTo("client")); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MethodConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MethodConfigTest.java new file mode 100644 index 00000000000..d3ca1814657 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MethodConfigTest.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.Constants; +import org.hamcrest.Matchers; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +public class MethodConfigTest { + @Test + public void testName() throws Exception { + MethodConfig method = new MethodConfig(); + method.setName("hello"); + assertThat(method.getName(), equalTo("hello")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters, not(hasKey("name"))); + } + + @Test + public void testStat() throws Exception { + MethodConfig method = new MethodConfig(); + method.setStat(10); + assertThat(method.getStat(), equalTo(10)); + } + + @Test + public void testRetry() throws Exception { + MethodConfig method = new MethodConfig(); + method.setRetry(true); + assertThat(method.isRetry(), is(true)); + } + + @Test + public void testReliable() throws Exception { + MethodConfig method = new MethodConfig(); + method.setReliable(true); + assertThat(method.isReliable(), is(true)); + } + + @Test + public void testExecutes() throws Exception { + MethodConfig method = new MethodConfig(); + method.setExecutes(10); + assertThat(method.getExecutes(), equalTo(10)); + } + + @Test + public void testDeprecated() throws Exception { + MethodConfig method = new MethodConfig(); + method.setDeprecated(true); + assertThat(method.getDeprecated(), is(true)); + } + + @Test + public void testArguments() throws Exception { + MethodConfig method = new MethodConfig(); + ArgumentConfig argument = new ArgumentConfig(); + method.setArguments(Collections.singletonList(argument)); + assertThat(method.getArguments(), contains(argument)); + assertThat(method.getArguments(), Matchers.hasSize(1)); + } + + @Test + public void testSticky() throws Exception { + MethodConfig method = new MethodConfig(); + method.setSticky(true); + assertThat(method.getSticky(), is(true)); + } + + @Test + public void testOnreturn() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOnreturn("on-return-object"); + assertThat(method.getOnreturn(), equalTo((Object) "on-return-object")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_RETURN_INSTANCE_KEY, (Object) "on-return-object")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testOnreturnMethod() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOnreturnMethod("on-return-method"); + assertThat(method.getOnreturnMethod(), equalTo("on-return-method")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_RETURN_METHOD_KEY, (Object) "on-return-method")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testOnthrow() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOnthrow("on-throw-object"); + assertThat(method.getOnthrow(), equalTo((Object) "on-throw-object")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_THROW_INSTANCE_KEY, (Object) "on-throw-object")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testOnthrowMethod() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOnthrowMethod("on-throw-method"); + assertThat(method.getOnthrowMethod(), equalTo("on-throw-method")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_THROW_METHOD_KEY, (Object) "on-throw-method")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testOninvoke() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOninvoke("on-invoke-object"); + assertThat(method.getOninvoke(), equalTo((Object) "on-invoke-object")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_INVOKE_INSTANCE_KEY, (Object) "on-invoke-object")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testOninvokeMethod() throws Exception { + MethodConfig method = new MethodConfig(); + method.setOninvokeMethod("on-invoke-method"); + assertThat(method.getOninvokeMethod(), equalTo("on-invoke-method")); + Map attribute = new HashMap(); + MethodConfig.appendAttributes(attribute, method); + assertThat(attribute, hasEntry((Object) Constants.ON_INVOKE_METHOD_KEY, (Object) "on-invoke-method")); + Map parameters = new HashMap(); + MethodConfig.appendParameters(parameters, method); + assertThat(parameters.size(), is(0)); + } + + @Test + public void testReturn() throws Exception { + MethodConfig method = new MethodConfig(); + method.setReturn(true); + assertThat(method.isReturn(), is(true)); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockCodec.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockCodec.java new file mode 100644 index 00000000000..51867ae008b --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockCodec.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.remoting.Channel; +import com.alibaba.dubbo.remoting.Codec; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class MockCodec implements Codec { + @Override + public void encode(Channel channel, OutputStream output, Object message) throws IOException { + + } + + @Override + public Object decode(Channel channel, InputStream input) throws IOException { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockDispatcher.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockDispatcher.java new file mode 100644 index 00000000000..7691f31150d --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockDispatcher.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.remoting.ChannelHandler; +import com.alibaba.dubbo.remoting.Dispatcher; + +public class MockDispatcher implements Dispatcher { + @Override + public ChannelHandler dispatch(ChannelHandler handler, URL url) { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockExchanger.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockExchanger.java new file mode 100644 index 00000000000..32ff0faad66 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockExchanger.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.exchange.ExchangeClient; +import com.alibaba.dubbo.remoting.exchange.ExchangeHandler; +import com.alibaba.dubbo.remoting.exchange.ExchangeServer; +import com.alibaba.dubbo.remoting.exchange.Exchanger; + +public class MockExchanger implements Exchanger { + @Override + public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException { + return null; + } + + @Override + public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockProtocol2.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockProtocol2.java new file mode 100644 index 00000000000..be819782a51 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockProtocol2.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.rpc.Exporter; +import com.alibaba.dubbo.rpc.Invoker; +import com.alibaba.dubbo.rpc.Protocol; +import com.alibaba.dubbo.rpc.RpcException; + +public class MockProtocol2 implements Protocol { + public static Protocol delegate; + + @Override + public int getDefaultPort() { + return delegate.getDefaultPort(); + } + + @Override + public Exporter export(Invoker invoker) throws RpcException { + return delegate.export(invoker); + } + + @Override + public Invoker refer(Class type, URL url) throws RpcException { + return delegate.refer(type, url); + } + + @Override + public void destroy() { + delegate.destroy(); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockStatusChecker.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockStatusChecker.java new file mode 100644 index 00000000000..29e77518377 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockStatusChecker.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.status.Status; +import com.alibaba.dubbo.common.status.StatusChecker; + +public class MockStatusChecker implements StatusChecker { + @Override + public Status check() { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTelnetHandler.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTelnetHandler.java new file mode 100644 index 00000000000..3c02f8c39d0 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTelnetHandler.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.remoting.Channel; +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.telnet.TelnetHandler; + +public class MockTelnetHandler implements TelnetHandler { + @Override + public String telnet(Channel channel, String message) throws RemotingException { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockThreadPool.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockThreadPool.java new file mode 100644 index 00000000000..ec6fc50355d --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockThreadPool.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.common.threadpool.ThreadPool; + +import java.util.concurrent.Executor; + +public class MockThreadPool implements ThreadPool { + @Override + public Executor getExecutor(URL url) { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTransporter.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTransporter.java new file mode 100644 index 00000000000..749b9095ef0 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MockTransporter.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.remoting.ChannelHandler; +import com.alibaba.dubbo.remoting.Client; +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.Server; +import com.alibaba.dubbo.remoting.Transporter; + +public class MockTransporter implements Transporter { + @Override + public Server bind(URL url, ChannelHandler handler) throws RemotingException { + return null; + } + + @Override + public Client connect(URL url, ChannelHandler handler) throws RemotingException { + return null; + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ModuleConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ModuleConfigTest.java new file mode 100644 index 00000000000..0d006296e70 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ModuleConfigTest.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertThat; + +public class ModuleConfigTest { + @Test(expected = IllegalStateException.class) + public void testName1() throws Exception { + ModuleConfig module = new ModuleConfig(); + Map parameters = new HashMap(); + ModuleConfig.appendParameters(parameters, module); + } + + @Test + public void testName2() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setName("module-name"); + assertThat(module.getName(), equalTo("module-name")); + assertThat(module.getId(), equalTo("module-name")); + Map parameters = new HashMap(); + ModuleConfig.appendParameters(parameters, module); + assertThat(parameters, hasEntry("module", "module-name")); + } + + @Test + public void testVersion() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setName("module-name"); + module.setVersion("1.0.0"); + assertThat(module.getVersion(), equalTo("1.0.0")); + Map parameters = new HashMap(); + ModuleConfig.appendParameters(parameters, module); + assertThat(parameters, hasEntry("module.version", "1.0.0")); + } + + @Test + public void testOwner() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setOwner("owner"); + assertThat(module.getOwner(), equalTo("owner")); + } + + @Test + public void testOrganization() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setOrganization("org"); + assertThat(module.getOrganization(), equalTo("org")); + } + + @Test + public void testRegistry() throws Exception { + ModuleConfig module = new ModuleConfig(); + RegistryConfig registry = new RegistryConfig(); + module.setRegistry(registry); + assertThat(module.getRegistry(), sameInstance(registry)); + } + + @Test + public void testRegistries() throws Exception { + ModuleConfig module = new ModuleConfig(); + RegistryConfig registry = new RegistryConfig(); + module.setRegistries(Collections.singletonList(registry)); + assertThat(module.getRegistries(), Matchers.hasSize(1)); + assertThat(module.getRegistries(), contains(registry)); + } + + @Test + public void testMonitor() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setMonitor("monitor-addr1"); + assertThat(module.getMonitor().getAddress(), equalTo("monitor-addr1")); + module.setMonitor(new MonitorConfig("monitor-addr2")); + assertThat(module.getMonitor().getAddress(), equalTo("monitor-addr2")); + } + + @Test + public void testDefault() throws Exception { + ModuleConfig module = new ModuleConfig(); + module.setDefault(true); + assertThat(module.isDefault(), is(true)); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MonitorConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MonitorConfigTest.java new file mode 100644 index 00000000000..49756af6ce2 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/MonitorConfigTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +public class MonitorConfigTest { + @Test + public void testAddress() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setAddress("monitor-addr"); + assertThat(monitor.getAddress(), equalTo("monitor-addr")); + Map parameters = new HashMap(); + MonitorConfig.appendParameters(parameters, monitor); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testProtocol() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setProtocol("protocol"); + assertThat(monitor.getProtocol(), equalTo("protocol")); + Map parameters = new HashMap(); + MonitorConfig.appendParameters(parameters, monitor); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testUsername() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setUsername("user"); + assertThat(monitor.getUsername(), equalTo("user")); + Map parameters = new HashMap(); + MonitorConfig.appendParameters(parameters, monitor); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testPassword() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setPassword("secret"); + assertThat(monitor.getPassword(), equalTo("secret")); + Map parameters = new HashMap(); + MonitorConfig.appendParameters(parameters, monitor); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testGroup() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setGroup("group"); + assertThat(monitor.getGroup(), equalTo("group")); + } + + @Test + public void testVersion() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setVersion("1.0.0"); + assertThat(monitor.getVersion(), equalTo("1.0.0")); + } + + @Test + public void testParameters() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + Map parameters = Collections.singletonMap("k1", "v1"); + monitor.setParameters(parameters); + assertThat(monitor.getParameters(), hasEntry("k1", "v1")); + } + + @Test + public void testDefault() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setDefault(true); + assertThat(monitor.isDefault(), is(true)); + } + + @Test + public void testInterval() throws Exception { + MonitorConfig monitor = new MonitorConfig(); + monitor.setInterval("100"); + assertThat(monitor.getInterval(), equalTo("100")); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProtocolConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProtocolConfigTest.java new file mode 100644 index 00000000000..43f3621e287 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProtocolConfigTest.java @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.extension.ExtensionLoader; +import com.alibaba.dubbo.rpc.Protocol; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +public class ProtocolConfigTest { + @Test + public void testDestroyAll() throws Exception { + Protocol protocol = Mockito.mock(Protocol.class); + MockProtocol2.delegate = protocol; + ExtensionLoader loader = ExtensionLoader.getExtensionLoader(Protocol.class); + loader.getExtension("mockprotocol2"); + ProtocolConfig.destroyAll(); + Mockito.verify(protocol).destroy(); + } + + @Test + public void testDestroy() throws Exception { + Protocol protocol = Mockito.mock(Protocol.class); + MockProtocol2.delegate = protocol; + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.setName("mockprotocol2"); + protocolConfig.destory(); + Mockito.verify(protocol).destroy(); + } + + @Test + public void testName() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setName("name"); + Map parameters = new HashMap(); + ProtocolConfig.appendParameters(parameters, protocol); + assertThat(protocol.getName(), equalTo("name")); + assertThat(protocol.getId(), equalTo("name")); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testHost() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setHost("host"); + Map parameters = new HashMap(); + ProtocolConfig.appendParameters(parameters, protocol); + assertThat(protocol.getHost(), equalTo("host")); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testPort() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setPort(8080); + Map parameters = new HashMap(); + ProtocolConfig.appendParameters(parameters, protocol); + assertThat(protocol.getPort(), equalTo(8080)); + assertThat(parameters.isEmpty(), is(true)); + } + + @Test + public void testPath() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setContextpath("context-path"); + Map parameters = new HashMap(); + ProtocolConfig.appendParameters(parameters, protocol); + assertThat(protocol.getPath(), equalTo("context-path")); + assertThat(protocol.getContextpath(), equalTo("context-path")); + assertThat(parameters.isEmpty(), is(true)); + protocol.setPath("path"); + assertThat(protocol.getPath(), equalTo("path")); + assertThat(protocol.getContextpath(), equalTo("path")); + } + + @Test + public void testThreads() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setThreads(10); + assertThat(protocol.getThreads(), is(10)); + } + + @Test + public void testIothreads() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setIothreads(10); + assertThat(protocol.getIothreads(), is(10)); + } + + @Test + public void testQueues() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setQueues(10); + assertThat(protocol.getQueues(), is(10)); + } + + @Test + public void testAccepts() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setAccepts(10); + assertThat(protocol.getAccepts(), is(10)); + } + + @Test + public void testCodec() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setName("dubbo"); + protocol.setCodec("mockcodec"); + assertThat(protocol.getCodec(), equalTo("mockcodec")); + } + + @Test + public void testAccesslog() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setAccesslog("access.log"); + assertThat(protocol.getAccesslog(), equalTo("access.log")); + } + + @Test + public void testTelnet() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setTelnet("mocktelnethandler"); + assertThat(protocol.getTelnet(), equalTo("mocktelnethandler")); + } + + @Test + public void testRegister() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setRegister(true); + assertThat(protocol.isRegister(), is(true)); + } + + @Test + public void testTransporter() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setTransporter("mocktransporter"); + assertThat(protocol.getTransporter(), equalTo("mocktransporter")); + } + + @Test + public void testExchanger() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setExchanger("mockexchanger"); + assertThat(protocol.getExchanger(), equalTo("mockexchanger")); + } + + @Test + public void testDispatcher() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setDispatcher("mockdispatcher"); + assertThat(protocol.getDispatcher(), equalTo("mockdispatcher")); + } + + @Test + public void testNetworker() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setNetworker("networker"); + assertThat(protocol.getNetworker(), equalTo("networker")); + } + + @Test + public void testParameters() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setParameters(Collections.singletonMap("k1", "v1")); + assertThat(protocol.getParameters(), hasEntry("k1", "v1")); + } + + @Test + public void testDefault() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setDefault(true); + assertThat(protocol.isDefault(), is(true)); + } + + @Test + public void testKeepAlive() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setKeepAlive(true); + assertThat(protocol.getKeepAlive(), is(true)); + } + + @Test + public void testOptimizer() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setOptimizer("optimizer"); + assertThat(protocol.getOptimizer(), equalTo("optimizer")); + } + + @Test + public void testExtension() throws Exception { + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setExtension("extension"); + assertThat(protocol.getExtension(), equalTo("extension")); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProviderConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProviderConfigTest.java new file mode 100644 index 00000000000..ce8b1b11aa3 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ProviderConfigTest.java @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.config; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +public class ProviderConfigTest { + @Test + public void testProtocol() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setProtocol("protocol"); + assertThat(provider.getProtocol().getName(), equalTo("protocol")); + } + + @Test + public void testDefault() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setDefault(true); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.isDefault(), is(true)); + assertThat(parameters, not(hasKey("default"))); + } + + @Test + public void testHost() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setHost("demo-host"); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.getHost(), equalTo("demo-host")); + assertThat(parameters, not(hasKey("host"))); + } + + @Test + public void testPort() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setPort(8080); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.getPort(), is(8080)); + assertThat(parameters, not(hasKey("port"))); + } + + @Test + public void testPath() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setPath("/path"); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.getPath(), equalTo("/path")); + assertThat(provider.getContextpath(), equalTo("/path")); + assertThat(parameters, not(hasKey("path"))); + } + + @Test + public void testContextPath() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setContextpath("/context-path"); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.getContextpath(), equalTo("/context-path")); + assertThat(parameters, not(hasKey("/context-path"))); + } + + @Test + public void testThreadpool() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setThreadpool("mockthreadpool"); + assertThat(provider.getThreadpool(), equalTo("mockthreadpool")); + } + + @Test + public void testThreads() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setThreads(10); + assertThat(provider.getThreads(), is(10)); + } + + @Test + public void testIothreads() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setIothreads(10); + assertThat(provider.getIothreads(), is(10)); + } + + @Test + public void testQueues() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setQueues(10); + assertThat(provider.getQueues(), is(10)); + } + + @Test + public void testAccepts() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setAccepts(10); + assertThat(provider.getAccepts(), is(10)); + } + + @Test + public void testCharset() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setCharset("utf-8"); + assertThat(provider.getCharset(), equalTo("utf-8")); + } + + @Test + public void testPayload() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setPayload(10); + assertThat(provider.getPayload(), is(10)); + } + + @Test + public void testBuffer() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setBuffer(10); + assertThat(provider.getBuffer(), is(10)); + } + + @Test + public void testServer() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setServer("demo-server"); + assertThat(provider.getServer(), equalTo("demo-server")); + } + + @Test + public void testClient() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setClient("client"); + assertThat(provider.getClient(), equalTo("client")); + } + + @Test + public void testTelnet() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setTelnet("mocktelnethandler"); + assertThat(provider.getTelnet(), equalTo("mocktelnethandler")); + } + + @Test + public void testPrompt() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setPrompt("#"); + Map parameters = new HashMap(); + ProviderConfig.appendParameters(parameters, provider); + assertThat(provider.getPrompt(), equalTo("#")); + assertThat(parameters, hasEntry("prompt", "%23")); + } + + @Test + public void testStatus() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setStatus("mockstatuschecker"); + assertThat(provider.getStatus(), equalTo("mockstatuschecker")); + } + + @Test + public void testTransporter() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setTransporter("mocktransporter"); + assertThat(provider.getTransporter(), equalTo("mocktransporter")); + } + + @Test + public void testExchanger() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setExchanger("mockexchanger"); + assertThat(provider.getExchanger(), equalTo("mockexchanger")); + } + + @Test + public void testDispatcher() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setDispatcher("mockdispatcher"); + assertThat(provider.getDispatcher(), equalTo("mockdispatcher")); + } + + @Test + public void testNetworker() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setNetworker("networker"); + assertThat(provider.getNetworker(), equalTo("networker")); + } + + @Test + public void testWait() throws Exception { + ProviderConfig provider = new ProviderConfig(); + provider.setWait(10); + assertThat(provider.getWait(), equalTo(10)); + } +} diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.status.StatusChecker b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.status.StatusChecker new file mode 100644 index 00000000000..14fc47be4ce --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.status.StatusChecker @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mockstatuschecker=com.alibaba.dubbo.config.MockStatusChecker \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool new file mode 100644 index 00000000000..3bfd1aba965 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mockthreadpool=com.alibaba.dubbo.config.MockThreadPool \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Codec b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Codec new file mode 100644 index 00000000000..df9bb1531d0 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Codec @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mockcodec=com.alibaba.dubbo.config.MockCodec \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Dispatcher b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Dispatcher new file mode 100644 index 00000000000..1b6be40d9cf --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Dispatcher @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mockdispatcher=com.alibaba.dubbo.config.MockDispatcher \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Transporter b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Transporter new file mode 100644 index 00000000000..d17c7847536 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.Transporter @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mocktransporter=com.alibaba.dubbo.config.MockTransporter \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.exchange.Exchanger b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.exchange.Exchanger new file mode 100644 index 00000000000..3a8ecb9484f --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.exchange.Exchanger @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mockexchanger=com.alibaba.dubbo.config.MockExchanger \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.telnet.TelnetHandler b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.telnet.TelnetHandler new file mode 100644 index 00000000000..28104b4bcf0 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.remoting.telnet.TelnetHandler @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +mocktelnethandler=com.alibaba.dubbo.config.MockTelnetHandler + diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.Protocol b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.Protocol index b95dc2e0942..30b82bf3a3e 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.Protocol +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.Protocol @@ -1 +1,2 @@ -mockprotocol=com.alibaba.dubbo.config.support.MockProtocol \ No newline at end of file +mockprotocol=com.alibaba.dubbo.config.support.MockProtocol +mockprotocol2=com.alibaba.dubbo.config.MockProtocol2 \ No newline at end of file