Skip to content

Commit

Permalink
clean up: finish unit test for config-api (apache#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
beiwei30 authored May 14, 2018
1 parent 24b34ed commit 5272859
Show file tree
Hide file tree
Showing 52 changed files with 192 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.config.api.Greeting;
import com.alibaba.dubbo.config.support.Parameter;
import junit.framework.TestCase;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.config.api.Greeting;
import com.alibaba.dubbo.config.mock.GreetingLocal1;
import com.alibaba.dubbo.config.mock.GreetingLocal2;
import com.alibaba.dubbo.config.mock.GreetingLocal3;
import com.alibaba.dubbo.config.mock.GreetingMock1;
import com.alibaba.dubbo.config.mock.GreetingMock2;
import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.registry.RegistryService;
import junit.framework.TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.alibaba.dubbo.config;

import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.config.mock.MockProtocol2;
import com.alibaba.dubbo.rpc.Protocol;
import org.junit.Test;
import org.mockito.Mockito;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.config.api.DemoService;
import com.alibaba.dubbo.config.api.Greeting;
import com.alibaba.dubbo.config.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.config.mock.MockProtocol2;
import com.alibaba.dubbo.config.mock.MockRegistryFactory2;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
Expand Down Expand Up @@ -55,7 +58,7 @@ public class ServiceConfigTest {
@Before
public void setUp() throws Exception {
MockProtocol2.delegate = protocolDelegate;
MockRegistryFactory.registry = registryDelegate;
MockRegistryFactory2.registry = registryDelegate;
Mockito.when(protocolDelegate.export(Mockito.any(Invoker.class))).thenReturn(exporter);

ApplicationConfig app = new ApplicationConfig("app");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
* (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
* 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;
package com.alibaba.dubbo.config.api;

import com.alibaba.dubbo.common.extension.SPI;

@SPI
interface Greeting {
public interface Greeting {
String hello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.invoker;

import com.alibaba.dubbo.config.api.Greeting;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;

public class DelegateProviderMetaDataInvokerTest {
private ServiceConfig service;
private Invoker<Greeting> invoker;

@Before
public void setUp() throws Exception {
service = Mockito.mock(ServiceConfig.class);
invoker = Mockito.mock(Invoker.class);
}

@Test
public void testDelegate() throws Exception {
DelegateProviderMetaDataInvoker<Greeting> delegate =
new DelegateProviderMetaDataInvoker<Greeting>(invoker, service);
delegate.getInterface();
Mockito.verify(invoker).getInterface();
delegate.getUrl();
Mockito.verify(invoker).getUrl();
delegate.isAvailable();
Mockito.verify(invoker).isAvailable();
Invocation invocation = Mockito.mock(Invocation.class);
delegate.invoke(invocation);
Mockito.verify(invoker).invoke(invocation);
delegate.destroy();
Mockito.verify(invoker).destroy();
assertThat(delegate.getMetadata(), sameInstance(service));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

class GreetingLocal1 {
public class GreetingLocal1 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

class GreetingLocal2 implements Greeting {
import com.alibaba.dubbo.config.api.Greeting;

public class GreetingLocal2 implements Greeting {
@Override
public String hello() {
return "local";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

class GreetingLocal3 implements Greeting {
import com.alibaba.dubbo.config.api.Greeting;

public class GreetingLocal3 implements Greeting {
private Greeting greeting;

public GreetingLocal3(Greeting greeting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

public class GreetingMock1 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.config.api.Greeting;

public class GreetingMock2 implements Greeting {
private GreetingMock2() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.dubbo.config;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.Codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.dubbo.config;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.ChannelHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.dubbo.config;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.RemotingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.dubbo.config;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.ExporterListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.InvokerListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.support;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Exporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.dubbo.config;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Exporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* (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
* 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;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.support;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.support;
package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.Registry;
Expand Down
Loading

0 comments on commit 5272859

Please sign in to comment.