This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new e4f757684 [type:test] Improve the unit test coverage of shenyu-client
(#3811)
e4f757684 is described below
commit e4f757684b815723c0891c3d52bd7440eac186a0
Author: yunlongn <[email protected]>
AuthorDate: Sat Aug 6 15:32:13 2022 +0800
[type:test] Improve the unit test coverage of shenyu-client (#3811)
* [type:test] Improve the unit test coverage of shenyu-client-springcloud
* [type:test] Improve the unit test coverage of shenyu-client-springcloud
* [type:test] Improve the unit test coverage of shenyu-client-tars
* [type:test] Improve the unit test coverage of shenyu-client-springmvc.
* [type:test] Improve the unit test coverage of shenyu-client-springmvc.
---
.../init/ContextRegisterListenerTest.java | 95 +++++++++++++++++++++
.../init/SpringCloudClientEventListenerTest.java | 15 +++-
.../init/ContextRegisterListenerTest.java | 96 ++++++++++++++++++++++
.../init/SpringMvcClientEventListenerTest.java | 54 +++++++++++-
.../TarsContextRefreshedEventListenerTest.java | 74 +++++++++++++++++
.../apache/shenyu/client/tars/TarsRpcExtTest.java | 56 +++++++++++++
.../tars/TarsServiceBeanPostProcessorTest.java | 28 ++++++-
7 files changed, 413 insertions(+), 5 deletions(-)
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListenerTest.java
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListenerTest.java
new file mode 100644
index 000000000..761550c53
--- /dev/null
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListenerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.shenyu.client.springcloud.init;
+
+import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
+import
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
+import org.apache.shenyu.common.utils.PortUtils;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
+import org.apache.shenyu.register.common.config.PropertiesConfig;
+import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.env.Environment;
+
+import java.util.Properties;
+
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Test for {@link ContextRegisterListener}.
+ */
+@ExtendWith(MockitoExtension.class)
+@TestMethodOrder(MethodOrderer.Alphanumeric.class)
+public final class ContextRegisterListenerTest {
+
+ private ContextRegisterListener contextRegisterListener;
+
+ @Mock
+ private Environment env;
+
+ @Mock
+ private PropertiesConfig config;
+
+ @Mock
+ private Properties properties;
+
+ @Mock
+ private BeanFactory beanFactory;
+
+ @BeforeEach
+ public void beforeEach() {
+ when(config.getProps()).thenReturn(properties);
+ when(properties.getProperty(ShenyuClientConstants.IS_FULL,
Boolean.FALSE.toString())).thenReturn(Boolean.TRUE.toString());
+
+ // hit throws
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new ContextRegisterListener(config, env));
+
+ // hit success
+
when(properties.getProperty(ShenyuClientConstants.CONTEXT_PATH)).thenReturn(ShenyuClientConstants.CONTEXT_PATH);
+ contextRegisterListener = new ContextRegisterListener(config, env);
+
+ ShenyuClientRegisterEventPublisher publisher =
ShenyuClientRegisterEventPublisher.getInstance();
+ publisher.start(mock(ShenyuClientRegisterRepository.class));
+ }
+
+ @Test
+ public void testSetBeanFactory() {
+ contextRegisterListener.setBeanFactory(beanFactory);
+ }
+
+ @Test
+ public void testOnApplicationEvent() {
+ MockedStatic<PortUtils> portUtilsMockedStatic =
mockStatic(PortUtils.class);
+ portUtilsMockedStatic.when(() ->
PortUtils.findPort(beanFactory)).thenReturn(8080);
+
contextRegisterListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+
contextRegisterListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+ }
+}
+
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java
index ce607105b..7d731365c 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java
@@ -17,11 +17,13 @@
package org.apache.shenyu.client.springcloud.init;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import
org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory;
import org.apache.shenyu.client.springcloud.annotation.ShenyuSpringCloudClient;
import org.apache.shenyu.register.client.http.utils.RegisterUtils;
import org.apache.shenyu.register.common.config.PropertiesConfig;
import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig;
+import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
@@ -128,17 +130,26 @@ public final class SpringCloudClientEventListenerTest {
mockRegisterCenter.setServerLists("http://127.0.0.1:8080");
mockRegisterCenter.setRegisterType("http");
mockRegisterCenter.setProps(properties);
+ // hit error
+ when(env.getProperty("spring.application.name")).thenReturn("");
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new SpringCloudClientEventListener(config,
ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env));
+
when(env.getProperty("spring.application.name")).thenReturn("spring-cloud-test");
return new SpringCloudClientEventListener(config,
ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env);
}
@RestController
@RequestMapping("/order")
- @ShenyuSpringCloudClient(path = "/order")
static class SpringCloudClientTestBean {
@PostMapping("/save")
- @ShenyuSpringCloudClient(path = "/save")
+ @ShenyuSpringCloudClient(path = "/order/save")
public String save(@RequestBody final String body) {
return "" + body;
}
+
+ @PostMapping("/update")
+ @ShenyuSpringCloudClient(path = "")
+ public String update(@RequestBody final String body) {
+ return "" + body;
+ }
}
}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListenerTest.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListenerTest.java
new file mode 100644
index 000000000..badd8a10e
--- /dev/null
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListenerTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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 org.apache.shenyu.client.springmvc.init;
+
+import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
+import
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.common.utils.PortUtils;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
+import org.apache.shenyu.register.common.config.PropertiesConfig;
+import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+import java.util.Properties;
+
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+
+/**
+ * Test for {@link ContextRegisterListener}.
+ */
+@ExtendWith(MockitoExtension.class)
+public class ContextRegisterListenerTest {
+
+ private ContextRegisterListener contextRegisterListener;
+
+ @Mock
+ private PropertiesConfig config;
+
+ @Mock
+ private Properties properties;
+
+ @Mock
+ private BeanFactory beanFactory;
+
+ @BeforeEach
+ public void beforeEach() {
+ when(config.getProps()).thenReturn(properties);
+ when(properties.getProperty(ShenyuClientConstants.IS_FULL,
Boolean.FALSE.toString())).thenReturn(Boolean.TRUE.toString());
+
+ // hit throws
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new ContextRegisterListener(config));
+
+ // hit success
+
when(properties.getProperty(ShenyuClientConstants.CONTEXT_PATH)).thenReturn(ShenyuClientConstants.CONTEXT_PATH);
+ contextRegisterListener = new ContextRegisterListener(config);
+
+ ShenyuClientRegisterEventPublisher publisher =
ShenyuClientRegisterEventPublisher.getInstance();
+ publisher.start(mock(ShenyuClientRegisterRepository.class));
+ }
+
+ @Test
+ public void testSetBeanFactory() {
+ contextRegisterListener.setBeanFactory(beanFactory);
+ }
+
+ @Test
+ public void testOnApplicationEvent() {
+ MockedStatic<PortUtils> portUtilsMockedStatic =
mockStatic(PortUtils.class);
+ portUtilsMockedStatic.when(() ->
PortUtils.findPort(beanFactory)).thenReturn(8080);
+
contextRegisterListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+
+ // hit `!registered.compareAndSet(false, true)`
+
contextRegisterListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+ portUtilsMockedStatic.close();
+ }
+
+ @Test
+ public void testOnApplicationEventError() {
+ Assert.assertThrows(ShenyuException.class, () ->
contextRegisterListener.onApplicationEvent(mock(ContextRefreshedEvent.class)));
+ }
+}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
index ebf288f8d..c7a7da844 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
@@ -17,11 +17,14 @@
package org.apache.shenyu.client.springmvc.init;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import
org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.client.http.utils.RegisterUtils;
import org.apache.shenyu.register.common.config.PropertiesConfig;
import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig;
+import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -41,10 +44,11 @@ import java.util.Optional;
import java.util.Properties;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.when;
/**
@@ -57,6 +61,12 @@ public class SpringMvcClientEventListenerTest {
private final SpringMvcClientTestBean springMvcClientTestBean = new
SpringMvcClientTestBean();
+ private final SpringMvcClientTestBean2 springMvcClientTestBean2 = new
SpringMvcClientTestBean2();
+
+ private final SpringMvcClientTestBean3 springMvcClientTestBean3 = new
SpringMvcClientTestBean3();
+
+ private final SpringMvcClientTestBean4 springMvcClientTestBean4 = new
SpringMvcClientTestBean4();
+
@Mock
private ApplicationContext applicationContext;
@@ -65,8 +75,16 @@ public class SpringMvcClientEventListenerTest {
private void init() {
Map<String, Object> results = new LinkedHashMap<>();
results.put("springMvcClientTestBean", springMvcClientTestBean);
+ results.put("springMvcClientTestBean2", springMvcClientTestBean2);
+ results.put("springMvcClientTestBean3", springMvcClientTestBean3);
+ results.put("springMvcClientTestBean4", springMvcClientTestBean4);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);
+ Properties properties = mock(Properties.class);
+
+ PropertiesConfig clientConfig = mock(PropertiesConfig.class);
+ when(clientConfig.getProps()).thenReturn(properties);
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new SpringMvcClientEventListener(clientConfig,
mock(ShenyuClientRegisterRepository.class)));
}
@Test
@@ -129,6 +147,40 @@ public class SpringMvcClientEventListenerTest {
public String hello(@RequestBody final String input) {
return "hello:" + input;
}
+
+ @GetMapping("/hello2")
+ @ShenyuSpringMvcClient(path = "")
+ public String hello2(@RequestBody final String input) {
+ return "hello:" + input;
+ }
+
+ @GetMapping("")
+ public String hello3(@RequestBody final String input) {
+ return "hello:" + input;
+ }
+ }
+
+ @RestController
+ @RequestMapping("/hello2/*")
+ static class SpringMvcClientTestBean2 {
+ public String test(final String hello) {
+ return hello + "";
+ }
+ }
+
+ @RestController
+ static class SpringMvcClientTestBean3 {
+ public String test(final String hello) {
+ return hello + "";
+ }
+ }
+
+ @RestController
+ @ShenyuSpringMvcClient(path = "/order/*")
+ static class SpringMvcClientTestBean4 {
+ public String test(final String hello) {
+ return hello + "";
+ }
}
}
diff --git
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsContextRefreshedEventListenerTest.java
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsContextRefreshedEventListenerTest.java
new file mode 100644
index 000000000..da963022b
--- /dev/null
+++
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsContextRefreshedEventListenerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.shenyu.client.tars;
+
+import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
+import
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
+import org.apache.shenyu.register.common.config.PropertiesConfig;
+import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+import java.util.Properties;
+
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Test case for {@link TarsContextRefreshedEventListener}.
+ */
+@ExtendWith(MockitoExtension.class)
+@TestMethodOrder(MethodOrderer.Alphanumeric.class)
+public class TarsContextRefreshedEventListenerTest {
+
+ private TarsContextRefreshedEventListener
tarsContextRefreshedEventListener;
+
+ @Mock
+ private PropertiesConfig clientConfig;
+
+ @BeforeEach
+ public void beforeEach() {
+ Properties properties = mock(Properties.class);
+ when(clientConfig.getProps()).thenReturn(properties);
+ // hit error
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new TarsContextRefreshedEventListener(clientConfig));
+
+
when(properties.getProperty(ShenyuClientConstants.CONTEXT_PATH)).thenReturn(ShenyuClientConstants.CONTEXT_PATH);
+
when(properties.getProperty(ShenyuClientConstants.HOST)).thenReturn(ShenyuClientConstants.HOST);
+
when(properties.getProperty(ShenyuClientConstants.PORT)).thenReturn("8899");
+ tarsContextRefreshedEventListener = new
TarsContextRefreshedEventListener(clientConfig);
+ ShenyuClientRegisterEventPublisher publisher =
ShenyuClientRegisterEventPublisher.getInstance();
+ publisher.start(mock(ShenyuClientRegisterRepository.class));
+ }
+
+ @Test
+ public void testOnApplicationEvent() {
+
tarsContextRefreshedEventListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+ // hit `registered.compareAndSet(false, true)`
+
tarsContextRefreshedEventListener.onApplicationEvent(mock(ContextRefreshedEvent.class));
+ }
+}
+
diff --git
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsRpcExtTest.java
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsRpcExtTest.java
new file mode 100644
index 000000000..f30dba8e2
--- /dev/null
+++
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsRpcExtTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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 org.apache.shenyu.client.tars;
+
+import org.apache.shenyu.client.tars.common.dto.TarsRpcExt;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test case for {@link TarsRpcExt}.
+ */
+@ExtendWith(MockitoExtension.class)
+@TestMethodOrder(MethodOrderer.Alphanumeric.class)
+public class TarsRpcExtTest {
+
+ @Test
+ public void testTarsRpcExt() {
+ TarsRpcExt.RpcExt rpcExt = new TarsRpcExt.RpcExt();
+ rpcExt.setMethodName("methodName");
+ rpcExt.setParams(null);
+ rpcExt.setReturnType("returnType");
+ final List<TarsRpcExt.RpcExt> rpcExtList = new ArrayList<>();
+ rpcExtList.add(rpcExt);
+ TarsRpcExt tarsRpcExt = new TarsRpcExt();
+ tarsRpcExt.setMethodInfo(rpcExtList);
+ Assertions.assertNotNull(tarsRpcExt.toString());
+ Assertions.assertNotNull(tarsRpcExt.getMethodInfo());
+ Assertions.assertNotNull(rpcExt.toString());
+ Assertions.assertNotNull(rpcExt.getMethodName());
+ Assertions.assertNotNull(rpcExt.getReturnType());
+ Assertions.assertNull(rpcExt.getParams());
+ }
+}
+
diff --git
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
index 42d5016ec..d4055cd7d 100644
---
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
+++
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
@@ -17,12 +17,15 @@
package org.apache.shenyu.client.tars;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import
org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory;
import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsClient;
import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsService;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.client.http.utils.RegisterUtils;
import org.apache.shenyu.register.common.config.PropertiesConfig;
import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig;
+import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
@@ -40,10 +43,11 @@ import java.util.Optional;
import java.util.Properties;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.times;
/**
* Test case for {@link TarsServiceBeanEventListener}.
@@ -55,6 +59,8 @@ public final class TarsServiceBeanPostProcessorTest {
private final TarsDemoService tarsDemoService = new TarsDemoService();
+ private final TarsDemoService2 tarsDemoService2 = new TarsDemoService2();
+
@Mock
private ApplicationContext applicationContext;
@@ -64,9 +70,14 @@ public final class TarsServiceBeanPostProcessorTest {
public void init() {
Map<String, Object> results = new LinkedHashMap();
results.put("tarsDemoService", tarsDemoService);
+ results.put("tarsDemoService2", tarsDemoService2);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);
+ Properties properties = mock(Properties.class);
+ PropertiesConfig clientConfig = mock(PropertiesConfig.class);
+ when(clientConfig.getProps()).thenReturn(properties);
+ Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new TarsServiceBeanEventListener(clientConfig,
mock(ShenyuClientRegisterRepository.class)));
}
@Test
@@ -111,5 +122,18 @@ public final class TarsServiceBeanPostProcessorTest {
public String test(final String hello) {
return hello + "";
}
+
+ @ShenyuTarsClient("hello2/*")
+ public String test2(final String hello) {
+ return hello + "";
+ }
+ }
+
+ @ShenyuTarsService(serviceName = "testObj2")
+ @ShenyuTarsClient("hello2/*")
+ static class TarsDemoService2 {
+ public String test(final String hello) {
+ return hello + "";
+ }
}
}