View Javadoc

1   /*
2    * $Id: TriggerNoArgsServiceMethodTestCase.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.test.cookbook.quartz;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  
17  import java.util.Arrays;
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  /**
27   * The Quartz transport can be used to trigger an event to be received by the
28   * component based on the endpoint configuration. In Mule an event is usually
29   * expected, however in this example we have a service component who's service method
30   * doesn't take any parameters. The
31   * {@link org.mule.transport.quartz.jobs.EventGeneratorJob} can be used to trigger a
32   * service method, and by not specifying a 'payload' element there is no data to try
33   * and match to the service method, so Mule will match a method with no arguments.
34   */
35  public class TriggerNoArgsServiceMethodTestCase extends AbstractServiceAndFlowTestCase
36  {
37      @Parameters
38      public static Collection<Object[]> parameters()
39      {
40          return Arrays.asList(new Object[][]{
41              {ConfigVariant.SERVICE, "org/mule/test/cookbook/quartz/trigger-no-args-method-config-service.xml"},
42              {ConfigVariant.FLOW, "org/mule/test/cookbook/quartz/trigger-no-args-method-config-flow.xml"}});
43      }
44  
45      public TriggerNoArgsServiceMethodTestCase(ConfigVariant variant, String configResources)
46      {
47          super(variant, configResources);
48      }
49  
50      @Test
51      public void testTrigger() throws Exception
52      {
53          MuleClient client = new MuleClient(muleContext);
54  
55          // Our method should have fired and we can pick up the result
56          MuleMessage result = client.request("resultQueue", 2000);
57  
58          // Always check method is not null. It wuld be rude not to!
59          assertNotNull(result);
60  
61          // Check we have a hit
62          assertEquals("Bullseye!", result.getPayloadAsString());
63      }
64  }