View Javadoc

1   /*
2    * $Id: IdempotentRouterWithFilterTestCase.java 22422 2011-07-15 08:22:16Z dirk.olmes $
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.inbound;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleException;
15  import org.mule.api.MuleMessage;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.AbstractServiceAndFlowTestCase;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertNull;
28  import static org.junit.Assert.fail;
29  
30  public class IdempotentRouterWithFilterTestCase extends AbstractServiceAndFlowTestCase
31  {
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{
36              {ConfigVariant.SERVICE, "org/mule/test/integration/routing/inbound/idempotent-router-with-filter-service.xml"},
37              {ConfigVariant.FLOW, "org/mule/test/integration/routing/inbound/idempotent-router-with-filter-flow.xml"}
38          });
39      }
40  
41      public IdempotentRouterWithFilterTestCase(ConfigVariant variant, String configResources)
42      {
43          super(variant, configResources);
44      }
45  
46      @Test
47      @SuppressWarnings("null")
48      public void testWithValidData()
49      {
50          /*
51           * This test will pass a message containing a String to the Mule server and
52           * verifies that it gets received.
53           */
54          MuleClient myClient;
55          DefaultMuleMessage myMessage = new DefaultMuleMessage("Mule is the best!", muleContext);
56          MuleMessage response = null;
57  
58          try
59          {
60              myClient = new MuleClient(muleContext);
61              myClient.dispatch("vm://FromTestCase", myMessage);
62              response = myClient.request("vm://ToTestCase", 5000);
63          }
64          catch (MuleException e)
65          {
66              fail(e.getDetailedMessage());
67          }
68  
69          assertNotNull(response);
70          assertNotNull(response.getPayload());
71          assertEquals("Mule is the best!", response.getPayload());
72      }
73  
74      @Test
75      public void testWithInvalidData()
76      {
77          /*
78           * This test will pass a message containing an Object to the Mule server and
79           * verifies that it does not get received.
80           */
81          MuleClient myClient;
82          DefaultMuleMessage myMessage = new DefaultMuleMessage(new Object(), muleContext);
83          MuleMessage response = null;
84  
85          try
86          {
87              myClient = new MuleClient(muleContext);
88              myClient.dispatch("vm://FromTestCase", myMessage);
89              response = myClient.request("vm://ToTestCase", 5000);
90          }
91          catch (MuleException e)
92          {
93              fail(e.getDetailedMessage());
94          }
95  
96          assertNull(response);
97      }
98  }