快速业务通道

在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 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号