Search in sources :

Example 1 with UrlHolder

use of com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension_noExtension.

@Test
public void test_urlHolder_getAdaptiveExtension_noExtension() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    UrlHolder holder = new UrlHolder();
    holder.setUrl(url);
    try {
        ext.echo(holder, "haha");
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Fail to get extension("));
    }
    url = url.addParameter("ext2", "XXX");
    holder.setUrl(url);
    try {
        ext.echo(holder, "haha");
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("No such extension"));
    }
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 2 with UrlHolder

use of com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension_ExceptionWhenNameNotProvided.

@Test
public void test_urlHolder_getAdaptiveExtension_ExceptionWhenNameNotProvided() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    UrlHolder holder = new UrlHolder();
    holder.setUrl(url);
    try {
        ext.echo(holder, "impl1");
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Fail to get extension("));
    }
    url = url.addParameter("key1", "impl1");
    holder.setUrl(url);
    try {
        ext.echo(holder, "haha");
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Fail to get extension(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) name from url"));
    }
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 3 with UrlHolder

use of com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension_UrlNpe.

@Test
public void test_urlHolder_getAdaptiveExtension_UrlNpe() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
    try {
        ext.echo(null, "haha");
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder argument == null", e.getMessage());
    }
    try {
        ext.echo(new UrlHolder(), "haha");
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder argument getUrl() == null", e.getMessage());
    }
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) Test(org.junit.Test)

Example 4 with UrlHolder

use of com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension.

@Test
public void test_urlHolder_getAdaptiveExtension() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
    Map<String, String> map = new HashMap<String, String>();
    map.put("ext2", "impl1");
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
    UrlHolder holder = new UrlHolder();
    holder.setUrl(url);
    String echo = ext.echo(holder, "haha");
    assertEquals("Ext2Impl1-echo", echo);
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

Ext2 (com.alibaba.dubbo.common.extensionloader.ext2.Ext2)4 UrlHolder (com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder)4 Test (org.junit.Test)4 URL (com.alibaba.dubbo.common.URL)3 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1