forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test for dubbo-config-api (apache#1733)
* finish unit test for AbstractMethodConfig * finish unit test for AbstractReferenceConfig * move to right package * finish unit test for AbstractReferenceConfig * finish unit test for AbstractMethodConfig * finish unit test for AbstractReferenceConfig * move to right package * finish unit test for AbstractReferenceConfig * unit test for AbstractServiceConfig, also fix logic issue in setListener/getListener
- Loading branch information
Showing
8 changed files
with
544 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...fig/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/AbstractMethodConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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.is; | ||
import static org.hamcrest.Matchers.isEmptyOrNullString; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class AbstractMethodConfigTest { | ||
@Test | ||
public void testTimeout() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setTimeout(10); | ||
assertThat(methodConfig.getTimeout(), equalTo(10)); | ||
} | ||
|
||
@Test | ||
public void testRetries() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setRetries(3); | ||
assertThat(methodConfig.getRetries(), equalTo(3)); | ||
} | ||
|
||
@Test | ||
public void testLoadbalance() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setLoadbalance("mockloadbalance"); | ||
assertThat(methodConfig.getLoadbalance(), equalTo("mockloadbalance")); | ||
} | ||
|
||
@Test | ||
public void testAsync() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setAsync(true); | ||
assertThat(methodConfig.isAsync(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testActives() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setActives(10); | ||
assertThat(methodConfig.getActives(), equalTo(10)); | ||
} | ||
|
||
@Test | ||
public void testSent() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setSent(true); | ||
assertThat(methodConfig.getSent(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testMock() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setMock((Boolean) null); | ||
assertThat(methodConfig.getMock(), isEmptyOrNullString()); | ||
methodConfig.setMock(true); | ||
assertThat(methodConfig.getMock(), equalTo("true")); | ||
methodConfig.setMock("return null"); | ||
assertThat(methodConfig.getMock(), equalTo("return null")); | ||
methodConfig.setMock("mock"); | ||
assertThat(methodConfig.getMock(), equalTo("mock")); | ||
} | ||
|
||
@Test | ||
public void testMerger() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setMerger("merger"); | ||
assertThat(methodConfig.getMerger(), equalTo("merger")); | ||
} | ||
|
||
@Test | ||
public void testCache() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setCache("cache"); | ||
assertThat(methodConfig.getCache(), equalTo("cache")); | ||
} | ||
|
||
@Test | ||
public void testValidation() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
methodConfig.setValidation("validation"); | ||
assertThat(methodConfig.getValidation(), equalTo("validation")); | ||
} | ||
|
||
@Test | ||
public void testParameters() throws Exception { | ||
MethodConfig methodConfig = new MethodConfig(); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
parameters.put("key", "value"); | ||
methodConfig.setParameters(parameters); | ||
assertThat(methodConfig.getParameters(), sameInstance(parameters)); | ||
} | ||
|
||
private static class MethodConfig extends AbstractMethodConfig { | ||
|
||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
.../dubbo-config-api/src/test/java/com/alibaba/dubbo/config/AbstractReferenceConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* 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.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasKey; | ||
import static org.hamcrest.Matchers.hasValue; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class AbstractReferenceConfigTest { | ||
|
||
@Test | ||
public void testCheck() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setCheck(true); | ||
assertThat(referenceConfig.isCheck(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testInit() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setInit(true); | ||
assertThat(referenceConfig.isInit(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testGeneric() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setGeneric(true); | ||
assertThat(referenceConfig.isGeneric(), is(true)); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
// FIXME: not sure why AbstractReferenceConfig has both isGeneric and getGeneric | ||
assertThat(parameters, hasKey("generic")); | ||
} | ||
|
||
@Test | ||
public void testInjvm() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setInit(true); | ||
assertThat(referenceConfig.isInit(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testFilter() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setFilter("mockfilter"); | ||
assertThat(referenceConfig.getFilter(), equalTo("mockfilter")); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
parameters.put(Constants.REFERENCE_FILTER_KEY, "prefilter"); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
assertThat(parameters, hasValue("prefilter,mockfilter")); | ||
} | ||
|
||
@Test | ||
public void testListener() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setListener("mockinvokerlistener"); | ||
assertThat(referenceConfig.getListener(), equalTo("mockinvokerlistener")); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
parameters.put(Constants.INVOKER_LISTENER_KEY, "prelistener"); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
assertThat(parameters, hasValue("prelistener,mockinvokerlistener")); | ||
} | ||
|
||
@Test | ||
public void testLazy() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setLazy(true); | ||
assertThat(referenceConfig.getLazy(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testOnconnect() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setOnconnect("onConnect"); | ||
assertThat(referenceConfig.getOnconnect(), equalTo("onConnect")); | ||
assertThat(referenceConfig.getStubevent(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testOndisconnect() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setOndisconnect("onDisconnect"); | ||
assertThat(referenceConfig.getOndisconnect(), equalTo("onDisconnect")); | ||
assertThat(referenceConfig.getStubevent(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testStubevent() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setOnconnect("onConnect"); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
assertThat(parameters, hasKey(Constants.STUB_EVENT_KEY)); | ||
} | ||
|
||
@Test | ||
public void testReconnect() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setReconnect("reconnect"); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
assertThat(referenceConfig.getReconnect(), equalTo("reconnect")); | ||
assertThat(parameters, hasKey(Constants.RECONNECT_KEY)); | ||
} | ||
|
||
@Test | ||
public void testSticky() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setSticky(true); | ||
Map<String, String> parameters = new HashMap<String, String>(); | ||
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); | ||
assertThat(referenceConfig.getSticky(), is(true)); | ||
assertThat(parameters, hasKey(Constants.CLUSTER_STICKY_KEY)); | ||
} | ||
|
||
@Test | ||
public void testVersion() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setVersion("version"); | ||
assertThat(referenceConfig.getVersion(), equalTo("version")); | ||
} | ||
|
||
@Test | ||
public void testGroup() throws Exception { | ||
ReferenceConfig referenceConfig = new ReferenceConfig(); | ||
referenceConfig.setGroup("group"); | ||
assertThat(referenceConfig.getGroup(), equalTo("group")); | ||
} | ||
|
||
private static class ReferenceConfig extends AbstractReferenceConfig { | ||
|
||
} | ||
} |
Oops, something went wrong.