1   /*
2    * $Id: ServerNotificationManagerTestCase.java 11181 2008-03-05 17:31:34Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.api.service.Service;
14  import org.mule.module.client.MuleClient;
15  
16  public class ServerNotificationManagerTestCase extends AbstractNotificationTestCase
17  {
18  
19      public static final String MULE_SYSTEM_MODEL = "_muleSystemModel";
20      public static final String MODEL = "the-model";
21      public static final String SERVICE = "the-service";
22  
23      protected String getConfigResources()
24      {
25          return "org/mule/test/integration/notifications/server-notification-manager-test.xml";
26      }
27  
28      public void doTest() throws Exception
29      {
30          MuleClient client = new MuleClient();
31          assertNotNull(client.send("vm://in", "hello world", null));
32          Service service = muleContext.getRegistry().lookupService(SERVICE);
33          service.pause();
34          service.resume();
35      }
36  
37      public RestrictedNode getSpecification()
38      {
39          return new Node()
40                  // all service events are asynchronous, so place parallel to rest
41                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_INITIALISED, SERVICE))
42                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STARTED, SERVICE))
43                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_PAUSED, SERVICE))
44                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_RESUMED, SERVICE))
45                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPING, SERVICE))
46                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPED, SERVICE))
47                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_DISPOSED, SERVICE))
48                  // synchronous events start here
49                  .parallel(new Node()
50                          // parallel because we don't know which model
51                          .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MULE_SYSTEM_MODEL)
52                                  .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MULE_SYSTEM_MODEL)))
53                          .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MODEL)
54                                  .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MODEL)))
55                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING))
56                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING_MODELS)
57                                  // parallel because we don't know which model
58                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MODEL)
59                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MODEL)))
60                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MULE_SYSTEM_MODEL)
61                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL))))
62                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED_MODELS))
63                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED))
64                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING))
65                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING))
66                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING_MODELS)
67                                  // parallel because we don't know which model
68                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MODEL)
69                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MODEL)))
70                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MULE_SYSTEM_MODEL)
71                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MULE_SYSTEM_MODEL))))
72                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED_MODELS))
73                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED))
74                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING_CONNECTORS))
75                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED_CONNECTORS)
76                                  // parallel because we don't know which model
77                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MODEL)
78                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MODEL)))
79                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MULE_SYSTEM_MODEL)
80                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MULE_SYSTEM_MODEL))))
81                            .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED)));
82      }
83  
84      public void validateSpecification(RestrictedNode spec) throws Exception
85      {
86          verifyAllNotifications(spec, ModelNotification.class,
87                  ModelNotification.MODEL_INITIALISING, ModelNotification.MODEL_INITIALISED);
88          // no model/listener notifications
89          verifyAllNotifications(spec, ModelNotification.class,
90                  ModelNotification.MODEL_STARTING, ModelNotification.MODEL_DISPOSED);
91          verifyAllNotifications(spec, ServiceNotification.class,
92                  ServiceNotification.SERVICE_INITIALISED, ServiceNotification.SERVICE_STOPPING);
93          // no manager initialising or initialised
94          verifyAllNotifications(spec, MuleContextNotification.class,
95                  MuleContextNotification.CONTEXT_STARTING, MuleContextNotification.CONTEXT_STOPPED_MODELS);
96      }
97  
98  }