View Javadoc

1   /*
2    * $Id: StatusCodeMappingsTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
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.junit4.AbstractMuleTestCase;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  public class StatusCodeMappingsTestCase extends AbstractMuleTestCase
25  {
26  
27      @Test
28      public void testErrorMappings()
29      {
30          String code = ExceptionHelper.getErrorMapping("http", RoutingException.class);
31          assertEquals("500", code);
32  
33          code = ExceptionHelper.getErrorMapping("HTTP", org.mule.api.security.SecurityException.class);
34          assertEquals("403", code);
35  
36          code = ExceptionHelper.getErrorMapping("http", UnauthorisedException.class);
37          assertEquals("401", code);
38  
39          code = ExceptionHelper.getErrorMapping("blah", DefaultMuleException.class);
40          assertEquals(
41              String.valueOf(new DefaultMuleException(MessageFactory.createStaticMessage("test")).getExceptionCode()), code);
42  
43      }
44  
45      @Test
46      public void testHttpsErrorMappings()
47      {
48          String code = ExceptionHelper.getErrorMapping("httpS", RoutingException.class);
49          assertEquals("500", code);
50  
51          code = ExceptionHelper.getErrorMapping("HTTPS", org.mule.api.security.SecurityException.class);
52          assertEquals("403", code);
53  
54          code = ExceptionHelper.getErrorMapping("https", UnauthorisedException.class);
55          assertEquals("401", code);
56      }
57  }