Skip to content

Commit

Permalink
整理ExtensionLoader UT
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jul 31, 2012
1 parent 786271c commit 254b7e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void test_getAdaptiveExtension_defaultAdaptiveKey() throws Exception {
}
}


@Test
public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
Expand All @@ -80,6 +79,47 @@ public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
assertEquals("Ext1Impl3-yell", echo);
}

@Test
public void test_getAdaptiveExtension_protocolKey() throws Exception {
UseProtocolKeyExt ext = ExtensionLoader.getExtensionLoader(UseProtocolKeyExt.class).getAdaptiveExtension();

{
String echo = ext.echo(URL.valueOf("1.2.3.4:20880"), "s");
assertEquals("Ext3Impl1-echo", echo); // 缺省值

Map<String, String> map = new HashMap<String, String>();
URL url = new URL("impl3", "1.2.3.4", 1010, "path1", map);

echo = ext.echo(url, "s");
assertEquals("Ext3Impl3-echo", echo); // 使用第2Key, Protocol

url = url.addParameter("key1", "impl2");
echo = ext.echo(url, "s");
assertEquals("Ext3Impl2-echo", echo); // 使用第1Key, key1
}

{

Map<String, String> map = new HashMap<String, String>();
URL url = new URL(null, "1.2.3.4", 1010, "path1", map);
String yell = ext.yell(url, "s");
assertEquals("Ext3Impl1-yell", yell); // 缺省值

url = url.addParameter("key2", "impl2"); // 使用第2Key, key2
yell = ext.yell(url, "s");
assertEquals("Ext3Impl2-yell", yell);

url = url.setProtocol("impl3"); // 使用第1Key, Protocol
yell = ext.yell(url, "d");
assertEquals("Ext3Impl3-yell", yell);
}
}

@Test
public void test_useJdkCompiler() throws Exception {

}

@Test
public void test_getAdaptiveExtension_UrlNpe() throws Exception {
SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
Expand Down Expand Up @@ -132,7 +172,7 @@ public void test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod() throws Ex
}

@Test
public void test_getAdaptiveExtension_ExceptionWhenNoUrlAttrib() throws Exception {
public void test_getAdaptiveExtension_ExceptionWhenNoUrlAttribute() throws Exception {
try {
ExtensionLoader.getExtensionLoader(NoUrlParamExt.class).getAdaptiveExtension();
fail();
Expand All @@ -141,42 +181,6 @@ public void test_getAdaptiveExtension_ExceptionWhenNoUrlAttrib() throws Exceptio
assertThat(expected.getMessage(), containsString(": not found url parameter or url attribute in parameters of method "));
}
}

@Test
public void test_getAdaptiveExtension_protocolKey() throws Exception {
UseProtocolKeyExt ext = ExtensionLoader.getExtensionLoader(UseProtocolKeyExt.class).getAdaptiveExtension();

{
String echo = ext.echo(URL.valueOf("1.2.3.4:20880"), "s");
assertEquals("Ext3Impl1-echo", echo); // 缺省值

Map<String, String> map = new HashMap<String, String>();
URL url = new URL("impl3", "1.2.3.4", 1010, "path1", map);

echo = ext.echo(url, "s");
assertEquals("Ext3Impl3-echo", echo); // 使用第2Key, Protocol

url = url.addParameter("key1", "impl2");
echo = ext.echo(url, "s");
assertEquals("Ext3Impl2-echo", echo); // 使用第1Key, key1
}

{

Map<String, String> map = new HashMap<String, String>();
URL url = new URL(null, "1.2.3.4", 1010, "path1", map);
String yell = ext.yell(url, "s");
assertEquals("Ext3Impl1-yell", yell); // 缺省值

url = url.addParameter("key2", "impl2"); // 使用第2Key, key2
yell = ext.yell(url, "s");
assertEquals("Ext3Impl2-yell", yell);

url = url.setProtocol("impl3"); // 使用第1Key, Protocol
yell = ext.yell(url, "d");
assertEquals("Ext3Impl3-yell", yell);
}
}

@Test
public void test_urlHolder_getAdaptiveExtension() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
* @author ding.lid
*/
public interface NoSpiExt {
// 没有使用key的@Adaptive !
@Adaptive
String echo(URL url, String s);

@Adaptive({"key1", "key2"})
String yell(URL url, String s);

// 无@Adaptive !
String bang(URL url, int i);
}

0 comments on commit 254b7e3

Please sign in to comment.