View Javadoc

1   /*
2    * $Id: BindingExceptionOnInterfaceMethodTestCase.java 22735 2011-08-25 16:02:35Z dfeist $
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.test.integration.routing.nested;
12  
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import org.mule.api.MuleMessage;
17  import org.mule.api.MuleRuntimeException;
18  import org.mule.config.i18n.MessageFactory;
19  import org.mule.tck.AbstractServiceAndFlowTestCase;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  public class BindingExceptionOnInterfaceMethodTestCase extends AbstractServiceAndFlowTestCase
28  {
29      private static final String PREFIX = "Exception in service component: ";
30  
31      @Parameters
32      public static Collection<Object[]> parameters()
33      {
34          return Arrays.asList(new Object[][]{
35              {ConfigVariant.SERVICE,
36                  "org/mule/test/integration/routing/nested/binding-exception-on-interface-method-service.xml"},
37              {ConfigVariant.FLOW,
38                  "org/mule/test/integration/routing/nested/binding-exception-on-interface-method-flow.xml"}});
39      }
40  
41      public BindingExceptionOnInterfaceMethodTestCase(ConfigVariant variant, String configResources)
42      {
43          super(variant, configResources);
44      }
45  
46      @Test
47      public void testExceptionOnBinding() throws Exception
48      {
49          MuleMessage reply = muleContext.getClient().send("vm://invoker.in", TEST_MESSAGE, null);
50          assertNotNull(reply);
51          String payload = reply.getPayloadAsString();
52          assertTrue(payload.contains("MuleRuntimeException"));
53          assertTrue(payload.contains(PREFIX));
54      }
55  
56      public static class Component
57      {
58          private BindigInterface binding;
59  
60          public String invoke(String payload)
61          {
62              try
63              {
64                  binding.process(payload, Integer.valueOf(0xC0DE));
65              }
66              catch (MuleRuntimeException muleException)
67              {
68                  return PREFIX + muleException.toString();
69              }
70  
71              return "ERROR, should not have come here";
72          }
73  
74          public BindigInterface getBinding()
75          {
76              return binding;
77          }
78  
79          public void setBinding(BindigInterface binding)
80          {
81              this.binding = binding;
82          }
83      }
84  
85      public static class ExceptionThrowingService
86      {
87          public String process(String s, Integer v)
88          {
89              throw new MuleRuntimeException(MessageFactory.createStaticMessage("Boom"));
90          }
91      }
92  
93      public interface BindigInterface
94      {
95          String process(String s, Integer v) throws MuleRuntimeException;
96      }
97  
98  }