Search in sources :

Example 21 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testCustomizeParameter.

@Test
@SuppressWarnings("unchecked")
public void testCustomizeParameter() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/customize-parameter.xml");
    context.start();
    ServiceBean<DemoService> serviceBean = (ServiceBean<DemoService>) context.getBean("demoServiceExport");
    URL url = (URL) serviceBean.getExportedUrls().get(0);
    assertEquals("protocol-paramA", url.getParameter("protocol.paramA"));
    assertEquals("service-paramA", url.getParameter("service.paramA"));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(org.apache.dubbo.config.spring.api.DemoService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 22 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testToString.

@Test
public void testToString() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setApplication(new ApplicationConfig("consumer"));
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:20881");
    String str = reference.toString();
    assertTrue(str.startsWith("<dubbo:reference "));
    assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" "));
    assertTrue(str.contains(" interface=\"org.apache.dubbo.config.spring.api.DemoService\" "));
    assertTrue(str.endsWith(" />"));
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 23 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testApiOverrideProperties.

@Test
public void testApiOverrideProperties() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("api-override-properties");
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("N/A");
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    protocol.setPort(13123);
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.setRegistry(registry);
    service.setProtocol(protocol);
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:13123");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).reference(reference).start();
    try {
        URL url = service.getExportedUrls().get(0);
        assertEquals("api-override-properties", url.getParameter("application"));
        assertEquals("world", url.getParameter("owner"));
        assertEquals(13123, url.getPort());
        url = reference.getExportedUrls().get(0);
        assertEquals("2000", url.getParameter("timeout"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 24 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testMultiProtocol.

@Test
public void testMultiProtocol() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20881");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 25 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideApi.

@Test
public void testSystemPropertyOverrideApi() throws Exception {
    System.setProperty("dubbo.application.name", "sysover");
    System.setProperty("dubbo.application.owner", "sysowner");
    System.setProperty("dubbo.registry.address", "N/A");
    System.setProperty("dubbo.protocol.name", "dubbo");
    System.setProperty("dubbo.protocol.port", "20834");
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("aaa");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("127.0.0.1");
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("rmi");
        protocol.setPort(1099);
        ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
        try {
            URL url = service.getExportedUrls().get(0);
            assertEquals("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            bootstrap.stop();
        }
    } finally {
        System.setProperty("dubbo.application.name", "");
        System.setProperty("dubbo.application.owner", "");
        System.setProperty("dubbo.registry.address", "");
        System.setProperty("dubbo.protocol.name", "");
        System.setProperty("dubbo.protocol.port", "");
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Aggregations

DemoService (org.apache.dubbo.config.spring.api.DemoService)30 Test (org.junit.jupiter.api.Test)27 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)12 RegistryConfig (org.apache.dubbo.config.RegistryConfig)12 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 ServiceConfig (org.apache.dubbo.config.ServiceConfig)10 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)8 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)7 URL (org.apache.dubbo.common.URL)6 RpcException (org.apache.dubbo.rpc.RpcException)4 HelloService (org.apache.dubbo.config.spring.api.HelloService)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)1 ProviderConfig (org.apache.dubbo.config.ProviderConfig)1 ConsumerConfiguration (org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration)1 TestConsumerConfiguration (org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration)1 HelloServiceImpl (org.apache.dubbo.config.spring.impl.HelloServiceImpl)1