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.test.integration.transport.jms.scripting;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  
18  /**
19   * Defines a scenario when we request a jms message from inside a groovy script
20   * which is executed as part of a service whose endpoints are jms ones.
21   * Subclasses must provide the service configuration through the implementation
22   * of {@link org.mule.tck.junit4.FunctionalTestCase#getConfigResources()}.
23   */
24  public abstract class AbstractJmsRequestFromScriptTestCase extends FunctionalTestCase
25  {
26  
27      /**
28       * Requests jms message from inside a groovy script which run as part of a
29       * service defined using jms endpoints. The first part of the test loads
30       * a couple of jms message in a queue so the script will have data to
31       * process.
32       */
33      @Test
34      public void testRequestingMessageFromScript() throws Exception
35      {
36          MuleClient muleClient = new MuleClient(muleContext);
37  
38          // Sends data to process
39          muleClient.send("vm://in", TEST_MESSAGE, null);
40          muleClient.send("vm://in", TEST_MESSAGE, null);
41  
42          // Sends the signal to start the batch process
43          muleClient.send("vm://startBatch", TEST_MESSAGE, null);
44  
45          // Checks that the batch has processed the two messages without error
46          MuleMessage message = muleClient.request("jms://status.queue?connector=jmsConnector", 5000);
47          assertNotNull(message);
48          assertEquals("messagemessage", message.getPayloadAsString());
49      }
50  }