在Spring基础上实现自己的异常处理框架 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-21
broker.setExceptionHandler(new ConsoleHandler()); 45 broker.setBeanFactory(beanFactory); 46 broker.execute("action", request, response); 47 } 48 49 }, BaseAppException.class); 50 } 51 52 public void testExceptionalAutoLoad() throws BaseAppException { 53 final BeanFactory beanFactory = context.mock(BeanFactory.class); 54 final BusinessAction<Response, Request> action = context 55 .mock(BusinessAction.class); 56 context.checking(new Expectations() { 57 { 58 allowing(beanFactory).getBean("action"); 59 will(returnValue(action)); 60 one(action).execute(request, response); 61 will(throwException(new ConfigException())); 62 } 63 }); 64 broker.setBeanFactory(beanFactory); 65 broker.execute("action", request, response); 66 assertEquals(CoreContextFactory.getInstance().getExceptionContext() 67 .getErrorCode(ConfigException.class), "LDD600-00002"); 68 context.assertIsSatisfied(); 69 } 70 71 public void testRuntimeException() { 72 final BusinessAction<Response, Request> action = context 73 .mock(BusinessAction.class); 74 final BeanFactory beanFactory = context.mock(BeanFactory.class); 75 assertThrowing(new Closure() { 76 public void run() throws Throwable { 77 context.checking(new Expectations() { 78 { 79 allowing(beanFactory).getBean("action"); 80 will(returnValue(action)); 81 one(action).execute(request, response); 82 will(throwException(new BaseAppRuntimeException())); 83 } 84 }); 85 broker.setExceptionHandler(new ConsoleHandler()); 86 broker.setBeanFactory(beanFactory); 87 broker.execute("action", request, response); 88 } 89 90 }, BaseAppRuntimeException.class); 91 // test config 92 assertEquals(CoreContextFactory.getInstance().getExceptionContext() 93 .getErrorCode(BaseAppRuntimeException.class), "LDD600-00001"); 94 // test handler 95 assertFalse(response.isSuccess()); 96 assertEquals(response.getErrorCode(), CoreContextFactory.getInstance() 97 .getExceptionContext().getErrorCode( 98 BaseAppRuntimeException.class)); 99 context.assertIsSatisfied(); 100 } 101 102 public void testCheckedException() { 103 final BusinessAction<Response, Request> action = context 104 .mock(BusinessAction.class); 105 final BeanFactory beanFactory = context.mock(BeanFactory.class); 106 assertThrowing(new Closure() { 107 public void run() throws Throwable { |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: ant简介 - 编程入门网下一篇: AOP下的权限控制实现 - 编程入门网
关于在Spring基础上实现自己的异常处理框架 - 编程入门网的所有评论