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.test.integration.routing.nested;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.MuleRuntimeException;
11  import org.mule.config.i18n.MessageFactory;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  public class BindingExceptionOnInterfaceMethodTestCase extends FunctionalTestCase
21  {
22  
23      private static final String PREFIX = "Exception in service component: ";
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/routing/nested/binding-exception-on-interface-method.xml";
29      }
30  
31      @Test
32      public void testExceptionOnBinding() throws Exception
33      {
34          MuleClient client = new MuleClient(muleContext);
35          MuleMessage reply = client.send("vm://invoker.in", TEST_MESSAGE, null);
36          assertNotNull(reply);
37          String payload = reply.getPayloadAsString();
38          assertTrue(payload.contains("MuleRuntimeException"));
39          assertTrue(payload.contains(PREFIX));
40      }
41  
42      public static class Component
43      {
44          private BindigInterface binding;
45          
46          public String invoke(String payload)
47          {
48              try
49              {
50                  binding.process(payload, Integer.valueOf(0xC0DE));
51              }
52              catch (MuleRuntimeException muleException)
53              {
54                  return PREFIX + muleException.toString();
55              }
56              
57              return "ERROR, should not have come here";
58          }
59  
60          public BindigInterface getBinding()
61          {
62              return binding;
63          }
64  
65          public void setBinding(BindigInterface binding)
66          {
67              this.binding = binding;
68          }
69      }
70      
71      public static class ExceptionThrowingService
72      {
73          public String process(String s, Integer v)
74          {
75              throw new MuleRuntimeException(MessageFactory.createStaticMessage("Boom"));
76          }
77      }
78      
79      public interface BindigInterface
80      {
81          String process(String s, Integer v) throws MuleRuntimeException;
82      }
83  
84  }
85  
86