use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class DefaultRpcProtocolTest method testProtocol.
@Test
public void testProtocol() {
url = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
url.getParameters().put(URLParamType.endpointFactory.getName(), "mockEndpoint");
try {
defaultRpcProtocol.export(null, null);
} catch (Exception e) {
if (e instanceof MotanFrameworkException) {
Assert.assertTrue(e.getMessage().contains("url is null"));
} else {
Assert.assertTrue(false);
}
}
try {
defaultRpcProtocol.export(null, url);
} catch (Exception e) {
if (e instanceof MotanFrameworkException) {
Assert.assertTrue(e.getMessage().contains("provider is null"));
} else {
Assert.assertTrue(false);
}
}
defaultRpcProtocol.export(new Provider<IHello>() {
@Override
public Response call(Request request) {
IHello hello = new Hello();
hello.hello();
return new DefaultResponse("hello");
}
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public boolean isAvailable() {
return false;
}
@Override
public String desc() {
return null;
}
@Override
public URL getUrl() {
return new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
}
@Override
public Class<IHello> getInterface() {
return IHello.class;
}
}, url);
Referer<IHello> referer = defaultRpcProtocol.refer(IHello.class, url);
DefaultRequest request = new DefaultRequest();
request.setMethodName("hello");
request.setInterfaceName(IHello.class.getName());
Response response = referer.call(request);
System.out.println("client: " + response.getValue());
defaultRpcProtocol.destroy();
}
Aggregations