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