View Javadoc

1   /*
2    * $Id: StatusCodeMappingsTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.http;
12  
13  import org.mule.api.DefaultMuleException;
14  import org.mule.api.routing.RoutingException;
15  import org.mule.api.security.UnauthorisedException;
16  import org.mule.config.ExceptionHelper;
17  import org.mule.config.i18n.MessageFactory;
18  import org.mule.tck.AbstractMuleTestCase;
19  
20  public class StatusCodeMappingsTestCase extends AbstractMuleTestCase
21  {
22      public void testErrorMappings()
23      {
24          String code = ExceptionHelper.getErrorMapping("http", RoutingException.class);
25          assertEquals("500", code);
26  
27          code = ExceptionHelper.getErrorMapping("HTTP", org.mule.api.security.SecurityException.class);
28          assertEquals("403", code);
29  
30          code = ExceptionHelper.getErrorMapping("http", UnauthorisedException.class);
31          assertEquals("401", code);
32  
33          code = ExceptionHelper.getErrorMapping("blah", DefaultMuleException.class);
34          assertEquals(
35              String.valueOf(new DefaultMuleException(MessageFactory.createStaticMessage("test")).getExceptionCode()), code);
36  
37      }
38  
39      public void testHttpsErrorMappings()
40      {
41          String code = ExceptionHelper.getErrorMapping("httpS", RoutingException.class);
42          assertEquals("500", code);
43  
44          code = ExceptionHelper.getErrorMapping("HTTPS", org.mule.api.security.SecurityException.class);
45          assertEquals("403", code);
46  
47          code = ExceptionHelper.getErrorMapping("https", UnauthorisedException.class);
48          assertEquals("401", code);
49      }
50  }