1   /*
2    * $Id: XmlFilterFunctionalTestCase.java 10969 2008-02-22 21:57:26Z holger $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.module.xml.functional;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  
16  import java.util.Random;
17  
18  public class XmlFilterFunctionalTestCase extends AbstractXmlFunctionalTestCase
19  {
20  
21      public static final int MAX_COUNT = 100;
22      public static final String STRING_MESSAGE = "Hello world";
23  
24      protected String getConfigResources()
25      {
26          return "org/mule/module/xml/xml-filter-functional-test.xml";
27      }
28  
29      public void testNotXml() throws Exception
30      {
31          logger.debug("not xml");
32          MuleClient client = new MuleClient();
33          client.dispatch("in", STRING_MESSAGE, null);
34          MuleMessage response = client.request("notxml", TIMEOUT);
35          assertNotNull(response);
36          assertNotNull(response.getPayload());
37          assertEquals(STRING_MESSAGE, response.getPayloadAsString());
38      }
39  
40      public void testOther() throws Exception
41      {
42          logger.debug("other");
43          doTestXml("other", getResourceAsString("org/mule/issues/many-sends-mule-1758-test.xml"));
44      }
45  
46      public void testSelf() throws Exception
47      {
48          logger.debug("self");
49          doTestXml("self", getConfigAsString());
50      }
51  
52      public void doTestXml(String endpoint, String xml) throws Exception
53      {
54          MuleClient client = new MuleClient();
55          client.dispatch("in", xml, null);
56          MuleMessage response = client.request(endpoint, TIMEOUT);
57          assertNotNull(response);
58          assertNotNull(response.getPayload());
59          assertEquals(xml, response.getPayloadAsString());
60      }
61  
62      public void testMany() throws Exception
63      {
64          Random random = new Random();
65          for (int i = 0; i < MAX_COUNT; ++i)
66          {
67              switch (random.nextInt(3))
68              {
69              case 0:
70                  testNotXml();
71                  break;
72              case 1:
73                  testOther();
74                  break;
75              case 2:
76                  testSelf();
77                  break;
78              default:
79                  throw new IllegalStateException("Bad case");
80              }
81          }
82      }
83  
84  }