View Javadoc

1   /*
2    * $Id: ComponentMessageNotificationTestCase.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.context.notification;
12  
13  import org.mule.module.client.MuleClient;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  
18  import org.junit.runners.Parameterized.Parameters;
19  
20  import static org.junit.Assert.assertNotNull;
21  
22  /**
23   * Test ComponentNotifications/Listeners by sending events to a component. A pre and
24   * post notification should be received by listeners.
25   */
26  public class ComponentMessageNotificationTestCase extends AbstractNotificationTestCase
27  {
28      @Parameters
29      public static Collection<Object[]> parameters()
30      {
31          return Arrays.asList(new Object[][]{
32              {ConfigVariant.SERVICE,
33                  "org/mule/test/integration/notifications/component-message-notification-test-service.xml"},
34              {ConfigVariant.FLOW,
35                  "org/mule/test/integration/notifications/component-message-notification-test-flow.xml"}});
36      }
37  
38      public ComponentMessageNotificationTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Override
44      public void doTest() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          assertNotNull(client.send("vm://in-1", "hello sweet world", null));
48          client.dispatch("vm://in-2", "goodbye cruel world", null);
49          assertNotNull(client.request("vm://out-2", 5000));
50      }
51  
52      @Override
53      public RestrictedNode getSpecification()
54      {
55          return new Node().parallel(
56              new Node(ComponentMessageNotification.class, ComponentMessageNotification.COMPONENT_PRE_INVOKE))
57              .parallel(
58                  new Node(ComponentMessageNotification.class,
59                      ComponentMessageNotification.COMPONENT_POST_INVOKE))
60              .parallel(
61                  new Node(ComponentMessageNotification.class,
62                      ComponentMessageNotification.COMPONENT_PRE_INVOKE))
63              .parallel(
64                  new Node(ComponentMessageNotification.class,
65                      ComponentMessageNotification.COMPONENT_POST_INVOKE));
66      }
67  
68      @Override
69      public void validateSpecification(RestrictedNode spec) throws Exception
70      {
71          verifyAllNotifications(spec, ComponentMessageNotification.class,
72              ComponentMessageNotification.COMPONENT_PRE_INVOKE,
73              ComponentMessageNotification.COMPONENT_POST_INVOKE);
74      }
75  }