use of com.weibo.api.motan.log.DefaultLogService in project motan by weibocom.
the class AccessLogFilterTest method testSwitcher.
public void testSwitcher() {
final Request request = mockery.mock(Request.class);
final Caller<IHello> caller = mockery.mock(Caller.class);
URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
url.addParameter(URLParamType.accessLog.getName(), String.valueOf(false));
final Map<String, String> attachments = new HashMap<>();
attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
final LogService logService = mockery.mock(LogService.class);
LoggerUtil.setLogService(logService);
mockery.checking(new Expectations() {
{
atLeast(1).of(caller).getUrl();
will(returnValue(url));
atLeast(1).of(caller).call(request);
}
});
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, true);
mockery.checking(new Expectations() {
{
exactly(1).of(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
exactly(1).of(request).getMethodName();
will(returnValue("get"));
exactly(1).of(request).getParamtersDesc();
will(returnValue("param_desc"));
atLeast(1).of(request).getAttachments();
will(returnValue(attachments));
exactly(1).of(logService).accessLog(with(any(String.class)));
allowing(request).getRequestId();
}
});
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, false);
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
LoggerUtil.setLogService(new DefaultLogService());
}
Aggregations