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  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.transport.NullPayload;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertFalse;
17  import static org.junit.Assert.assertNotNull;
18  
19  public abstract class AbstractXmlPropertyExtractorTestCase extends FunctionalTestCase
20  {
21      private boolean matchSingle = true;
22  
23      protected AbstractXmlPropertyExtractorTestCase(boolean matchSingle)
24      {
25          this.matchSingle = matchSingle;
26      }
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/module/xml/property-extractor-test.xml";
32      }
33  
34      protected abstract Object getMatchMessage() throws Exception;
35  
36      protected abstract Object getErrorMessage() throws Exception;
37  
38      @Test
39      public void testMatch() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
42          client.dispatch("vm://in", getMatchMessage(), null);
43          MuleMessage message = client.request("vm://match1", RECEIVE_TIMEOUT);
44  
45          assertNotNull(message);
46          assertFalse(message.getPayload() instanceof NullPayload);
47          if(!matchSingle)
48          {
49              message = client.request("vm://match2", RECEIVE_TIMEOUT);
50              assertNotNull(message);
51              assertFalse(message.getPayload() instanceof NullPayload);
52          }
53      }
54  
55      @Test
56      public void testError() throws Exception
57      {
58          MuleClient client = new MuleClient(muleContext);
59          client.dispatch("vm://in", getErrorMessage(), null);
60          MuleMessage message = client.request("vm://error", RECEIVE_TIMEOUT);
61          assertNotNull(message);
62          assertFalse(message.getPayload() instanceof NullPayload);
63      }
64      
65  }