diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java index b611c060196..559553e7404 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java @@ -24,11 +24,14 @@ import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.RegistryConfig; +import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; +import java.util.Map; + /** * {@link EnableDubboConfig} Test * @@ -92,6 +95,14 @@ public void testMultiple() { ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); + Map protocolConfigs = context.getBeansOfType(ProtocolConfig.class); + + for (Map.Entry entry : protocolConfigs.entrySet()) { + String beanName = entry.getKey(); + ProtocolConfig protocol = entry.getValue(); + Assert.assertEquals(beanName, protocol.getName()); + } + } @EnableDubboConfig diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java deleted file mode 100644 index 6ed8a857528..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScanRegistrar; -import org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration; -import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl; -import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.aop.support.AopUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.transaction.annotation.Transactional; - -import static org.springframework.core.annotation.AnnotationUtils.findAnnotation; - -/** - * {@link DubboComponentScanRegistrar} Test - * - * @since 2.5.8 - */ -public class DubboComponentScanRegistrarTest { - - @Test - public void test() { - - AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext(); - - providerContext.register(ProviderConfiguration.class); - - providerContext.refresh(); - - DemoService demoService = providerContext.getBean(DemoService.class); - - String value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - Class beanClass = AopUtils.getTargetClass(demoService); - - // DemoServiceImpl with @Transactional - Assertions.assertEquals(DemoServiceImpl.class, beanClass); - - // Test @Transactional is present or not - Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class)); - - AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(); - - consumerContext.register(ConsumerConfiguration.class); - - consumerContext.refresh(); - - ConsumerConfiguration consumerConfiguration = consumerContext.getBean(ConsumerConfiguration.class); - - demoService = consumerConfiguration.getDemoService(); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class); - - // From Child - - demoService = child.getDemoServiceFromChild(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - Assertions.assertEquals("Hello,Mercy", child.getDemoService().sayName("Mercy")); - - // From Parent - - demoService = child.getDemoServiceFromParent(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - // From Ancestor - - demoService = child.getDemoServiceFromAncestor(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - providerContext.close(); - consumerContext.close(); - - - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java deleted file mode 100644 index 48c06d4b47d..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -/** - * {@link DubboConfigBindingRegistrar} - * - * @since 2.5.8 - */ -public class DubboConfigBindingRegistrarTest { - - @Test - public void testRegisterBeanDefinitionsForSingle() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestApplicationConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - - } - - @Test - public void testRegisterBeanDefinitionsForMultiple() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestMultipleApplicationConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - applicationConfig = context.getBean("applicationBean2", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application2", applicationConfig.getName()); - - applicationConfig = context.getBean("applicationBean3", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application3", applicationConfig.getName()); - - - } - - @EnableDubboConfigBinding(prefix = "${application.prefixes}", type = ApplicationConfig.class, multiple = true) - @PropertySource("META-INF/config.properties") - private static class TestMultipleApplicationConfig { - - } - - @EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class) - @PropertySource("META-INF/config.properties") - private static class TestApplicationConfig { - - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java deleted file mode 100644 index f09782913d3..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingsRegistrar; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBindings; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -/** - * {@link DubboConfigBindingsRegistrar} Test - * - * @since DubboConfigBindingsRegistrar - */ -public class DubboConfigBindingsRegistrarTest { - - @Test - public void test() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - Assertions.assertEquals(2, context.getBeansOfType(ApplicationConfig.class).size()); - - } - - - @EnableDubboConfigBindings({ - @EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class), - @EnableDubboConfigBinding(prefix = "dubbo.applications.applicationBean", type = ApplicationConfig.class) - }) - @PropertySource("META-INF/config.properties") - private static class TestConfig { - - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java deleted file mode 100644 index d4f28aae301..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.core.io.support.ResourcePropertySource; - -import java.io.IOException; - -/** - * {@link DubboConfigConfiguration} Test - * - * @since 2.5.8 - */ -public class DubboConfigConfigurationTest { - - private AnnotationConfigApplicationContext context; - - @BeforeEach - public void before() throws IOException { - - context = new AnnotationConfigApplicationContext(); - ResourcePropertySource propertySource = new ResourcePropertySource("META-INF/config.properties"); - context.getEnvironment().getPropertySources().addFirst(propertySource); - - } - - @AfterEach - public void after() { - context.close(); - } - - @Test - public void testSingle() throws IOException { - - context.register(DubboConfigConfiguration.Single.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - // module - ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class); - Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName()); - - // registry - RegistryConfig registryConfig = context.getBean(RegistryConfig.class); - Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress()); - - // protocol - ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class); - Assertions.assertEquals("dubbo", protocolConfig.getName()); - Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort()); - } - - @Test - public void testMultiple() { - - context.register(DubboConfigConfiguration.Multiple.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName()); - - ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); - - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java deleted file mode 100644 index 691f251dac6..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.MonitorConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.ProviderConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; - -import org.junit.Assert; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -import java.util.Map; - -/** - * {@link EnableDubboConfig} Test - * - * @since 2.5.8 - */ -public class EnableDubboConfigTest { - - @Test - public void testSingle() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(TestConfig.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - // module - ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class); - Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName()); - - // registry - RegistryConfig registryConfig = context.getBean(RegistryConfig.class); - Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress()); - - // protocol - ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class); - Assertions.assertEquals("dubbo", protocolConfig.getName()); - Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort()); - - // monitor - MonitorConfig monitorConfig = context.getBean(MonitorConfig.class); - Assertions.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress()); - - // provider - ProviderConfig providerConfig = context.getBean(ProviderConfig.class); - Assertions.assertEquals("127.0.0.1", providerConfig.getHost()); - - - // consumer - ConsumerConfig consumerConfig = context.getBean(ConsumerConfig.class); - Assertions.assertEquals("netty", consumerConfig.getClient()); - - } - - @Test - public void testMultiple() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(TestMultipleConfig.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName()); - - ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); - - Map protocolConfigs = context.getBeansOfType(ProtocolConfig.class); - - for (Map.Entry entry : protocolConfigs.entrySet()) { - String beanName = entry.getKey(); - ProtocolConfig protocol = entry.getValue(); - Assert.assertEquals(beanName, protocol.getName()); - } - - } - - @EnableDubboConfig - @PropertySource("META-INF/config.properties") - private static class TestMultipleConfig { - - } - - @EnableDubboConfig(multiple = false) - @PropertySource("META-INF/config.properties") - private static class TestConfig { - - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java deleted file mode 100644 index 1366a35d252..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation; - -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration; -import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.aop.support.AopUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionException; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.annotation.Transactional; - -import static org.springframework.core.annotation.AnnotationUtils.findAnnotation; - -/** - * {@link EnableDubbo} Test - * - * @since 2.5.8 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {EnableDubboTest.class}) -@TestPropertySource(locations = "classpath:/META-INF/dubbb-provider.properties", - properties = "demo.service.version = 2.5.7") -@EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider") -@ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider") -@EnableTransactionManagement -public class EnableDubboTest { - - @Autowired - private ApplicationContext providerContext; - - @Test - public void test() { - - DemoService demoService = providerContext.getBean(DemoService.class); - - String value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - Class beanClass = AopUtils.getTargetClass(demoService); - - // DemoServiceImpl with @Transactional - Assert.assertEquals(DemoServiceImpl.class, beanClass); - - // Test @Transactional is present or not - Assert.assertNotNull(findAnnotation(beanClass, Transactional.class)); - - AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(TestConsumerConfiguration.class); - - TestConsumerConfiguration consumerConfiguration = consumerContext.getBean(TestConsumerConfiguration.class); - - demoService = consumerConfiguration.getDemoService(); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - TestConsumerConfiguration.Child child = consumerContext.getBean(TestConsumerConfiguration.Child.class); - - // From Child - - demoService = child.getDemoServiceFromChild(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // From Parent - - demoService = child.getDemoServiceFromParent(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // From Ancestor - - demoService = child.getDemoServiceFromAncestor(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // Test my-registry2 bean presentation - RegistryConfig registryConfig = consumerContext.getBean("my-registry2", RegistryConfig.class); - - // Test multiple binding - Assert.assertEquals("N/A", registryConfig.getAddress()); - - } - - @EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider") - @ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider") - @PropertySource("classpath:/META-INF/dubbb-provider.properties") - @EnableTransactionManagement - public static class TestProviderConfiguration { - - @Primary - @Bean - public PlatformTransactionManager platformTransactionManager() { - return new PlatformTransactionManager() { - - @Override - public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { - return null; - } - - @Override - public void commit(TransactionStatus status) throws TransactionException { - - } - - @Override - public void rollback(TransactionStatus status) throws TransactionException { - - } - }; - } - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java deleted file mode 100644 index 04866986197..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.consumer; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.annotation.Reference; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -@Configuration("consumerConfiguration") -@DubboComponentScan( - basePackageClasses = ConsumerConfiguration.class -) -@PropertySource("META-INF/default.properties") -public class ConsumerConfiguration { - - /** - * Current application configuration, to replace XML config: - * - * <dubbo:application name="dubbo-demo-application"/> - * - * - * @return {@link ApplicationConfig} Bean - */ - @Bean("dubbo-demo-application") - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(); - applicationConfig.setName("dubbo-demo-application"); - return applicationConfig; - } - - /** - * Current registry center configuration, to replace XML config: - * - * <dubbo:registry address="N/A"/> - * - * - * @return {@link RegistryConfig} Bean - */ - @Bean - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setAddress("N/A"); - return registryConfig; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoService; - - public DemoService getDemoService() { - return demoService; - } - - public void setDemoService(DemoService demoService) { - this.demoService = demoService; - } - - - @Bean - public Child c() { - return new Child(); - } - - public static abstract class Ancestor { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoServiceFromAncestor; - - public DemoService getDemoServiceFromAncestor() { - return demoServiceFromAncestor; - } - - public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) { - this.demoServiceFromAncestor = demoServiceFromAncestor; - } - } - - public static abstract class Parent extends Ancestor { - - private DemoService demoServiceFromParent; - - public DemoService getDemoServiceFromParent() { - return demoServiceFromParent; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - public void setDemoServiceFromParent(DemoService demoServiceFromParent) { - this.demoServiceFromParent = demoServiceFromParent; - } - - } - - public static class Child extends Parent { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoServiceFromChild; - - public DemoService getDemoServiceFromChild() { - return demoServiceFromChild; - } - - public void setDemoServiceFromChild(DemoService demoServiceFromChild) { - this.demoServiceFromChild = demoServiceFromChild; - } - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java deleted file mode 100644 index dc41c614cd8..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.consumer.test; - -import org.apache.dubbo.config.annotation.Reference; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.PropertySource; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -/** - * Test Consumer Configuration - * - * @since 2.5.7 - */ -@EnableDubbo(scanBasePackageClasses = TestConsumerConfiguration.class, multipleConfig = true) -@PropertySource("META-INF/dubbb-consumer.properties") -@EnableTransactionManagement -public class TestConsumerConfiguration { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoService; - - public DemoService getDemoService() { - return demoService; - } - - public void setDemoService(DemoService demoService) { - this.demoService = demoService; - } - - - @Bean - public TestConsumerConfiguration.Child c() { - return new TestConsumerConfiguration.Child(); - } - - public static abstract class Ancestor { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoServiceFromAncestor; - - public DemoService getDemoServiceFromAncestor() { - return demoServiceFromAncestor; - } - - public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) { - this.demoServiceFromAncestor = demoServiceFromAncestor; - } - } - - public static abstract class Parent extends TestConsumerConfiguration.Ancestor { - - private DemoService demoServiceFromParent; - - public DemoService getDemoServiceFromParent() { - return demoServiceFromParent; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - public void setDemoServiceFromParent(DemoService demoServiceFromParent) { - this.demoServiceFromParent = demoServiceFromParent; - } - - } - - public static class Child extends TestConsumerConfiguration.Parent { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoServiceFromChild; - - public DemoService getDemoServiceFromChild() { - return demoServiceFromChild; - } - - public void setDemoServiceFromChild(DemoService demoServiceFromChild) { - this.demoServiceFromChild = demoServiceFromChild; - } - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java deleted file mode 100644 index 8277bc9b4e8..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.spring.annotation.merged.MergedService; -import org.apache.dubbo.config.spring.api.HelloService; - -import org.springframework.stereotype.Service; - -/** - * Default {@link HelloService} annotation with Spring's {@link Service} - * and Dubbo's {@link org.apache.dubbo.config.annotation.Service} - * - * @since TODO - */ -@Service -//@org.apache.dubbo.config.annotation.Service -@MergedService -public class DefaultHelloService implements HelloService { - - @Override - public String sayHello(String name) { - return "Greeting, " + name; - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java deleted file mode 100644 index 155bd2a5539..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.spring.api.Box; -import org.apache.dubbo.config.spring.api.DemoService; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - - -/** - * {@link DemoService} Service implementation - * - * @since 2.5.8 - */ -@org.apache.dubbo.config.annotation.Service( - version = "${demo.service.version}", - application = "${demo.service.application}", - protocol = "${demo.service.protocol}", - registry = "${demo.service.registry}" -) -@Service -@Transactional -public class DemoServiceImpl implements DemoService { - - @Override - public String sayName(String name) { - return "Hello," + name; - } - - @Override - public Box getBox() { - return new Box() { - @Override - public String getName() { - return "MyBox"; - } - }; - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java deleted file mode 100644 index 10b00a8f5b3..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.annotation.Service; -import org.apache.dubbo.config.spring.api.HelloService; - -/** - * {@link HelloService} Implementation just annotating Dubbo's {@link Service} - * - * @since 2.5.9 - */ -@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService") -public class HelloServiceImpl implements HelloService { - - @Override - public String sayHello(String name) { - return "Hello, " + name; - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java deleted file mode 100644 index 9c45d7134a5..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.PropertySource; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionException; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@DubboComponentScan(basePackages = "org.apache.dubbo") -@ComponentScan(basePackages = "org.apache.dubbo") -@PropertySource("META-INF/default.properties") -@EnableTransactionManagement -public class ProviderConfiguration { - - /** - * Current application configuration, to replace XML config: - * - * <dubbo:application name="dubbo-demo-application"/> - * - * - * @return {@link ApplicationConfig} Bean - */ - @Bean("dubbo-demo-application") - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(); - applicationConfig.setName("dubbo-demo-application"); - return applicationConfig; - } - - /** - * Current registry center configuration, to replace XML config: - * - * <dubbo:registry id="my-registry" address="N/A"/> - * - * - * @return {@link RegistryConfig} Bean - */ - @Bean("my-registry") - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setAddress("N/A"); - return registryConfig; - } - - /** - * Current protocol configuration, to replace XML config: - * - * <dubbo:protocol name="dubbo" port="12345"/> - * - * - * @return {@link ProtocolConfig} Bean - */ - @Bean("dubbo") - public ProtocolConfig protocolConfig() { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setName("dubbo"); - protocolConfig.setPort(12345); - return protocolConfig; - } - - @Primary - @Bean - public PlatformTransactionManager platformTransactionManager() { - return new PlatformTransactionManager() { - - @Override - public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { - return null; - } - - @Override - public void commit(TransactionStatus status) throws TransactionException { - - } - - @Override - public void rollback(TransactionStatus status) throws TransactionException { - - } - }; - } - -} - diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java deleted file mode 100644 index 1caddb0b31b..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.dubbo.config.spring.context.context.properties; - - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.beans.factory.config.YamlPropertySourceFactory; -import org.apache.dubbo.config.spring.context.properties.DefaultDubboConfigBinder; -import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@TestPropertySource(locations = "classpath:/dubbo.properties") -@PropertySource(name = "yaml-source", value = {"classpath:/META-INF/dubbo.yml"}, factory = YamlPropertySourceFactory.class) -@Configuration -@ContextConfiguration(classes = {DefaultDubboConfigBinder.class, DefaultDubboConfigBinderTest.class}) -public class DefaultDubboConfigBinderTest { - - @Autowired - private DubboConfigBinder dubboConfigBinder; - - @Value("${dubbo.consumer.default}") - private Boolean isDefault; - - @Value("${dubbo.consumer.client}") - private String client; - - @Value("${dubbo.consumer.threadpool}") - private String threadPool; - - @Value("${dubbo.consumer.corethreads}") - private Integer coreThreads; - - @Value("${dubbo.consumer.threads}") - private Integer threads; - - @Value("${dubbo.consumer.queues}") - private Integer queues; - - @Test - public void testBinder() { - - ApplicationConfig applicationConfig = new ApplicationConfig(); - dubboConfigBinder.bind("dubbo.application", applicationConfig); - Assert.assertEquals("hello", applicationConfig.getName()); - Assert.assertEquals("world", applicationConfig.getOwner()); - - RegistryConfig registryConfig = new RegistryConfig(); - dubboConfigBinder.bind("dubbo.registry", registryConfig); - Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); - - ProtocolConfig protocolConfig = new ProtocolConfig(); - dubboConfigBinder.bind("dubbo.protocol", protocolConfig); - Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); - - ConsumerConfig consumerConfig = new ConsumerConfig(); - dubboConfigBinder.bind("dubbo.consumer", consumerConfig); - - Assert.assertEquals(isDefault, consumerConfig.isDefault()); - Assert.assertEquals(client, consumerConfig.getClient()); - Assert.assertEquals(threadPool, consumerConfig.getThreadpool()); - Assert.assertEquals(coreThreads, consumerConfig.getCorethreads()); - Assert.assertEquals(threads, consumerConfig.getThreads()); - Assert.assertEquals(queues, consumerConfig.getQueues()); - } -} -