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.inbound;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleException;
11  import org.mule.api.MuleMessage;
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.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertNull;
20  import static org.junit.Assert.fail;
21  
22  public class IdempotentRouterWithFilterTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/routing/inbound/idempotent-router-with-filter.xml";
29      }
30  
31      @Test
32      public void testWithValidData()
33      {
34          /*
35           * This test will pass a message containing a String to the Mule server and
36           * verifies that it gets received.
37           */
38          MuleClient myClient;
39          DefaultMuleMessage myMessage = new DefaultMuleMessage("Mule is the best!", muleContext);
40          MuleMessage response = null;
41  
42          try
43          {
44              myClient = new MuleClient(muleContext);
45              myClient.dispatch("vm://FromTestCase", myMessage);
46              response = myClient.request("vm://ToTestCase", 5000);
47          }
48          catch (MuleException e)
49          {
50              fail(e.getDetailedMessage());
51          }
52  
53          assertNotNull(response);
54          assertNotNull(response.getPayload());
55          assertEquals("Mule is the best!", response.getPayload());
56      }
57  
58      @Test
59      public void testWithInvalidData()
60      {
61          /*
62           * This test will pass a message containing an Object to the Mule server and
63           * verifies that it does not get received.
64           */
65          MuleClient myClient;
66          DefaultMuleMessage myMessage = new DefaultMuleMessage(new Object(), muleContext);
67          MuleMessage response = null;
68  
69          try
70          {
71              myClient = new MuleClient(muleContext);
72              myClient.dispatch("vm://FromTestCase", myMessage);
73              response = myClient.request("vm://ToTestCase", 5000);
74          }
75          catch (MuleException e)
76          {
77              fail(e.getDetailedMessage());
78          }
79  
80          assertNull(response);
81      }
82  
83  }