Search in sources :

Example 16 with ServiceConfig

use of com.alibaba.dubbo.config.ServiceConfig 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);
        service.export();
        try {
            URL url = service.toUrls().get(0);
            assertEquals("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            service.unexport();
        }
    } 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(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) ProtocolConfig(com.alibaba.dubbo.config.ProtocolConfig) URL(com.alibaba.dubbo.common.URL) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Aggregations

ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)16 Test (org.junit.Test)16 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)11 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)10 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)9 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)8 URL (com.alibaba.dubbo.common.URL)7 DemoServiceImpl (com.alibaba.dubbo.config.spring.impl.DemoServiceImpl)6 RpcException (com.alibaba.dubbo.rpc.RpcException)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 GenericService (com.alibaba.dubbo.rpc.service.GenericService)3 Date (java.util.Date)3 GenericException (com.alibaba.dubbo.rpc.service.GenericException)2 ConsumerConfig (com.alibaba.dubbo.config.ConsumerConfig)1 ProviderConfig (com.alibaba.dubbo.config.ProviderConfig)1 MockRegistry (com.alibaba.dubbo.config.spring.registry.MockRegistry)1 Registry (com.alibaba.dubbo.registry.Registry)1 HashMap (java.util.HashMap)1