View Javadoc

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