This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new b194bb0  Add tests for reference tag attribute (#8114)
b194bb0 is described below

commit b194bb0ea7d2fe632eb57a46fce544b4225aa2ab
Author: Gong Dewei <[email protected]>
AuthorDate: Wed Jun 23 10:46:36 2021 +0800

    Add tests for reference tag attribute (#8114)
---
 .../org/apache/dubbo/config/spring/ConfigTest.java |  9 +++++++--
 .../ReferenceAnnotationBeanPostProcessorTest.java  | 23 +++++++++++++++-------
 .../apache/dubbo/config/spring/init-reference.xml  |  2 +-
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
index d0a3035..23f4a56 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
@@ -410,12 +410,17 @@ public class ConfigTest {
 
     @Test
     public void testInitReference() throws Exception {
-        ClassPathXmlApplicationContext providerContext = new 
ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.',
 '/') + "/demo-provider.xml");
+        String configPath = 
ConfigTest.class.getPackage().getName().replace('.', '/');
+        ClassPathXmlApplicationContext providerContext = new 
ClassPathXmlApplicationContext(configPath + "/demo-provider.xml", 
configPath+"/demo-provider-properties.xml");
         providerContext.start();
         try {
-            ClassPathXmlApplicationContext ctx = new 
ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.',
 '/') + "/init-reference.xml");
+            ClassPathXmlApplicationContext ctx = new 
ClassPathXmlApplicationContext(configPath + "/init-reference.xml");
             ctx.start();
             try {
+
+                ReferenceBean referenceBean = ctx.getBean("&demoService", 
ReferenceBean.class);
+                Assertions.assertEquals("demo_tag", referenceBean.getTag());
+
                 DemoService demoService = (DemoService) 
ctx.getBean("demoService");
                 assertEquals("say:world", demoService.sayName("world"));
             } finally {
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java
index f8855cc..cf7ed17 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.config.spring.beans.factory.annotation;
 
+import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.config.annotation.Argument;
 import org.apache.dubbo.config.annotation.Method;
 import org.apache.dubbo.config.annotation.Reference;
@@ -23,6 +24,7 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.ReferenceBean;
 import org.apache.dubbo.config.spring.api.DemoService;
 import org.apache.dubbo.config.spring.api.HelloService;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import org.apache.dubbo.config.utils.ReferenceConfigCache;
 
 import org.aspectj.lang.ProceedingJoinPoint;
@@ -56,6 +58,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
  *
  * @since 2.5.7
  */
+@EnableDubbo(scanBasePackages = 
"org.apache.dubbo.config.spring.context.annotation.provider")
 @ExtendWith(SpringExtension.class)
 @ContextConfiguration(
         classes = {
@@ -64,7 +67,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
                 ReferenceAnnotationBeanPostProcessorTest.TestAspect.class
         })
 @TestPropertySource(properties = {
-        "packagesToScan = 
org.apache.dubbo.config.spring.context.annotation.provider",
+        "packagesToScan = nopackage",
         "consumer.version = ${demo.service.version}",
         "consumer.url = dubbo://127.0.0.1:12345?version=2.5.7",
 })
@@ -94,11 +97,6 @@ public class ReferenceAnnotationBeanPostProcessorTest {
         return new TestBean();
     }
 
-    @Bean(BEAN_NAME)
-    public ReferenceAnnotationBeanPostProcessor 
referenceAnnotationBeanPostProcessor() {
-        return new ReferenceAnnotationBeanPostProcessor();
-    }
-
     @Autowired
     private ConfigurableApplicationContext context;
 
@@ -115,7 +113,7 @@ public class ReferenceAnnotationBeanPostProcessorTest {
     private HelloService helloService;
 
     // #5 ReferenceBean (Field Injection #3)
-    @Reference
+    @Reference(id="helloService2", tag = "demo_tag")
     private HelloService helloService2;
 
     // Instance 1
@@ -203,6 +201,17 @@ public class ReferenceAnnotationBeanPostProcessorTest {
 
         
Assertions.assertNotNull(ReferenceConfigCache.getCache().get(referenceBean));
 
+        ReferenceBean helloService2Bean = getReferenceBean("helloService2", 
referenceBeans);
+        Assertions.assertEquals("demo_tag", helloService2Bean.getTag());
+    }
+
+    private ReferenceBean getReferenceBean(String name, 
Collection<ReferenceBean<?>> referenceBeans) {
+        for (ReferenceBean<?> referenceBean : referenceBeans) {
+            if (StringUtils.isEquals(name, referenceBean.getId())) {
+                return referenceBean;
+            }
+        }
+        return null;
     }
 
     @Test
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/init-reference.xml
 
b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/init-reference.xml
index 360922f..f90030b 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/init-reference.xml
+++ 
b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/init-reference.xml
@@ -26,6 +26,6 @@
 
     <!-- service configuration -->
     <dubbo:reference id="demoService" 
interface="org.apache.dubbo.config.spring.api.DemoService"
-                     url="dubbo://127.0.0.1:20813" init="true" scope="remote"/>
+                     url="dubbo://127.0.0.1:20813" init="true" scope="remote" 
tag="demo_tag"/>
 
 </beans>
\ No newline at end of file

Reply via email to