View Javadoc

1   /*
2    * $Id:AbstractExternalTransactionTestCase.java 8215 2007-09-05 16:56:51Z aperepel $
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.vm.functional.transactions;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.mule.api.DefaultMuleException;
16  import org.mule.api.MuleEvent;
17  import org.mule.api.MuleException;
18  import org.mule.api.MuleMessage;
19  import org.mule.api.processor.MessageProcessor;
20  import org.mule.module.client.MuleClient;
21  import org.mule.tck.FunctionalTestCase;
22  import org.mule.transport.NullPayload;
23  
24  /** Test transaction behavior when "joinExternal" is set to disallow joining external transactions
25   * There is one test per legal transactional behavior (e.g. ALWAYS_BEGIN).
26   */
27  public class MessageFilterTestCase extends FunctionalTestCase
28  {
29      protected static final Log logger = LogFactory.getLog(MessageFilterTestCase.class);
30  
31      private static String rejectMesage;
32  
33      @Override
34      protected String getConfigResources()
35      {
36          return "org/mule/test/config/message-filter-config.xml";
37      }
38  
39      /** Check that the configuration specifies considers external transactions */
40      public void testConfiguration() throws Exception
41      {
42          MuleClient client = new MuleClient(muleContext);
43          
44          MuleMessage response = client.send("vm://order.validation", "OK", null);
45          assertTrue(response.getPayload() instanceof NullPayload);
46          assertEquals("OK(rejected!-1)", rejectMesage);
47          
48          response = client.send("vm://order.validation", "OK-ABC", null);
49          assertTrue(response.getPayload() instanceof NullPayload);
50          assertEquals("OK-ABC(rejected!-2)", rejectMesage);
51          
52          response = client.send("vm://order.validation", "OK-DEF", null);
53          assertTrue(response.getPayload() instanceof NullPayload);
54          assertEquals("OK-DEF(rejected!-1)", rejectMesage);
55          rejectMesage = null;
56          
57          response = client.send("vm://order.validation", "OK-ABC-DEF", null);
58          assertEquals("OK-ABC-DEF(success)", response.getPayloadAsString());
59          assertNull(rejectMesage);
60      }
61  
62      public static class Reject1 implements MessageProcessor
63      {
64          public void setName(String name)
65          {
66          }
67  
68          public MuleEvent process(MuleEvent event) throws MuleException
69          {
70              try
71              {
72                  MuleMessage msg = event.getMessage();
73                  String payload = msg.getPayloadAsString();
74                  rejectMesage = payload + "(rejected!-1)";
75                  return null;
76              }
77              catch (Exception e)
78              {
79                  throw new DefaultMuleException(e);
80              }
81          }
82      }
83  
84       public static class Reject2 implements MessageProcessor
85       {
86           public void setName(String name)
87           {
88           }
89  
90          public MuleEvent process(MuleEvent event) throws MuleException
91          {
92              try
93              {
94                  MuleMessage msg = event.getMessage();
95                  String payload = msg.getPayloadAsString();
96                  rejectMesage = payload + "(rejected!-2)";
97                  return null;
98              }
99              catch (Exception e)
100             {
101                 throw new DefaultMuleException(e);
102             }
103         }
104     }
105 }