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