Search in sources :

Example 1 with SimpleExt

use of com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt in project dubbo by alibaba.

the class ExtensionLoaderTest method test_getDefaultExtension.

@Test
public void test_getDefaultExtension() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getDefaultExtension();
    assertThat(ext, instanceOf(SimpleExtImpl1.class));
    String name = ExtensionLoader.getExtensionLoader(SimpleExt.class).getDefaultExtensionName();
    assertEquals("impl1", name);
}
Also used : SimpleExtImpl1(com.alibaba.dubbo.common.extensionloader.ext1.impl.SimpleExtImpl1) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) Test(org.junit.Test)

Example 2 with SimpleExt

use of com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_getAdaptiveExtension_UrlNpe.

@Test
public void test_getAdaptiveExtension_UrlNpe() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
    try {
        ext.echo(null, "haha");
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("url == null", e.getMessage());
    }
}
Also used : SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) Test(org.junit.Test)

Example 3 with SimpleExt

use of com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod.

@Test
public void test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
    Map<String, String> map = new HashMap<String, String>();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
    try {
        ext.bang(url, 33);
        fail();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("method "));
        assertThat(expected.getMessage(), containsString("of interface com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt is not adaptive method!"));
    }
}
Also used : HashMap(java.util.HashMap) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 4 with SimpleExt

use of com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt in project dubbo by alibaba.

the class ExtensionLoaderTest method test_AddExtension_ExceptionWhenExistedExtension.

@Test
public void test_AddExtension_ExceptionWhenExistedExtension() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getExtension("impl1");
    try {
        ExtensionLoader.getExtensionLoader(AddExt1.class).addExtension("impl1", AddExt1_ManualAdd1.class);
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Extension name impl1 already existed(Extension interface com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt1)!"));
    }
}
Also used : SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) AddExt1(com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt1) Test(org.junit.Test)

Example 5 with SimpleExt

use of com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt in project dubbo by alibaba.

the class ExtensionLoader_Adaptive_Test method test_getAdaptiveExtension_customizeAdaptiveKey.

@Test
public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
    Map<String, String> map = new HashMap<String, String>();
    map.put("key2", "impl2");
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
    String echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl2-yell", echo);
    // note: URL is value's type
    url = url.addParameter("key1", "impl3");
    echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl3-yell", echo);
}
Also used : HashMap(java.util.HashMap) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

SimpleExt (com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt)5 Test (org.junit.Test)5 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)3 URL (com.alibaba.dubbo.common.URL)2 HashMap (java.util.HashMap)2 SimpleExtImpl1 (com.alibaba.dubbo.common.extensionloader.ext1.impl.SimpleExtImpl1)1 AddExt1 (com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt1)1