View Javadoc

1   /*
2    * $Id: AbstractXmlPropertyExtractorTestCase.java 22421 2011-07-15 05:05:06Z 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.module.xml.functional;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  import org.mule.transport.NullPayload;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  
24  import static org.junit.Assert.assertFalse;
25  import static org.junit.Assert.assertNotNull;
26  
27  public abstract class AbstractXmlPropertyExtractorTestCase extends AbstractServiceAndFlowTestCase
28  {
29      @Parameters
30      public static Collection<Object[]> parameters()
31      {
32          return Arrays.asList(new Object[][]{
33              {ConfigVariant.SERVICE, "org/mule/module/xml/property-extractor-test.xml"}
34  
35          });
36      }
37  
38      public AbstractXmlPropertyExtractorTestCase(ConfigVariant variant, String configResources, boolean matchSingle)
39      {
40          super(variant, configResources);
41          this.matchSingle = matchSingle;
42      }
43  
44      private boolean matchSingle = true;
45  
46      protected abstract Object getMatchMessage() throws Exception;
47  
48      protected abstract Object getErrorMessage() throws Exception;
49  
50      @Test
51      public void testMatch() throws Exception
52      {
53          MuleClient client = new MuleClient(muleContext);
54          client.dispatch("vm://in", getMatchMessage(), null);
55          MuleMessage message = client.request("vm://match1", RECEIVE_TIMEOUT);
56  
57          assertNotNull(message);
58          assertFalse(message.getPayload() instanceof NullPayload);
59          if(!matchSingle)
60          {
61              message = client.request("vm://match2", RECEIVE_TIMEOUT);
62              assertNotNull(message);
63              assertFalse(message.getPayload() instanceof NullPayload);
64          }
65      }
66  
67      @Test
68      public void testError() throws Exception
69      {
70          MuleClient client = new MuleClient(muleContext);
71          client.dispatch("vm://in", getErrorMessage(), null);
72          MuleMessage message = client.request("vm://error", RECEIVE_TIMEOUT);
73          assertNotNull(message);
74          assertFalse(message.getPayload() instanceof NullPayload);
75      }
76  }