Search in sources :

Example 1 with ConsumerConfiguration

use of org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration in project dubbo by alibaba.

the class DubboComponentScanRegistrarTest method test.

@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);
    // 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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ConsumerConfiguration(org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration) DemoService(org.apache.dubbo.config.spring.api.DemoService) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.jupiter.api.Test)

Aggregations

DemoService (org.apache.dubbo.config.spring.api.DemoService)1 ConsumerConfiguration (org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration)1 Test (org.junit.jupiter.api.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Transactional (org.springframework.transaction.annotation.Transactional)1