|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.dubbo.config.spring.beans.factory.annotation; |
| 18 | + |
| 19 | +import org.apache.dubbo.config.annotation.Reference; |
| 20 | +import org.apache.dubbo.config.annotation.Service; |
| 21 | +import org.apache.dubbo.config.spring.annotation.merged.MergedReference; |
| 22 | +import org.apache.dubbo.config.spring.annotation.merged.MergedService; |
| 23 | +import org.apache.dubbo.config.spring.api.DemoService; |
| 24 | +import org.junit.Assert; |
| 25 | +import org.junit.Test; |
| 26 | +import org.springframework.core.annotation.AnnotatedElementUtils; |
| 27 | +import org.springframework.util.ReflectionUtils; |
| 28 | +import java.lang.reflect.Field; |
| 29 | + |
| 30 | +public class MergedAnnotationTest { |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testMergedReference() { |
| 34 | + Field field = ReflectionUtils.findField(MergedAnnotationTest.TestBean1.class, "demoService"); |
| 35 | + Reference reference = AnnotatedElementUtils.getMergedAnnotation(field, Reference.class); |
| 36 | + Assert.assertEquals("dubbo", reference.group()); |
| 37 | + Assert.assertEquals("1.0.0", reference.version()); |
| 38 | + |
| 39 | + Field field2 = ReflectionUtils.findField(MergedAnnotationTest.TestBean2.class, "demoService"); |
| 40 | + Reference reference2 = AnnotatedElementUtils.getMergedAnnotation(field2, Reference.class); |
| 41 | + Assert.assertEquals("group", reference2.group()); |
| 42 | + Assert.assertEquals("2.0", reference2.version()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testMergedService() { |
| 47 | + Service service1 = AnnotatedElementUtils.getMergedAnnotation(MergedAnnotationTest.DemoServiceImpl1.class, Service.class); |
| 48 | + Assert.assertEquals("dubbo", service1.group()); |
| 49 | + Assert.assertEquals("1.0.0", service1.version()); |
| 50 | + |
| 51 | + Service service2 = AnnotatedElementUtils.getMergedAnnotation(MergedAnnotationTest.DemoServiceImpl2.class, Service.class); |
| 52 | + Assert.assertEquals("group", service2.group()); |
| 53 | + Assert.assertEquals("2.0", service2.version()); |
| 54 | + } |
| 55 | + |
| 56 | + @MergedService |
| 57 | + public static class DemoServiceImpl1 { |
| 58 | + } |
| 59 | + |
| 60 | + @MergedService(group = "group", version = "2.0") |
| 61 | + public static class DemoServiceImpl2 { |
| 62 | + } |
| 63 | + |
| 64 | + private static class TestBean1 { |
| 65 | + @MergedReference |
| 66 | + private DemoService demoService; |
| 67 | + } |
| 68 | + |
| 69 | + private static class TestBean2 { |
| 70 | + @MergedReference(group = "group", version = "2.0") |
| 71 | + private DemoService demoService; |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments