View Javadoc

1   /*
2    * $Id: ServerNotificationManagerTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.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(muleContext);
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_STOPPED, SERVICE))
46                  .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_DISPOSED, SERVICE))
47                  // synchronous events start here
48                  .parallel(new Node()
49                          // parallel because we don't know which model
50                          .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MULE_SYSTEM_MODEL))
51                                  .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MODEL))
52                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING))
53                          .serial(new Node()
54                                  // parallel because we don't know which model
55                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MODEL))
56                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL))
57                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL)))
58                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED))
59                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING))
60                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING))
61                          .serial(new Node()
62                                  // parallel because we don't know which model
63                                  .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MULE_SYSTEM_MODEL))
64                                          .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MODEL)))
65                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED)
66                                  // parallel because we don't know which model
67                                          .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MODEL))
68                                          .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MULE_SYSTEM_MODEL)))
69                            .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED)));
70      }
71  
72  //Before
73  //    public RestrictedNode getSpecificationx()
74  //    {
75  //        return new Node()
76  //                // all service events are asynchronous, so place parallel to rest
77  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_INITIALISED, SERVICE))
78  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STARTED, SERVICE))
79  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_PAUSED, SERVICE))
80  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_RESUMED, SERVICE))
81  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPED, SERVICE))
82  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPED, SERVICE))
83  //                .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_DISPOSED, SERVICE))
84  //                // synchronous events start here
85  //                .parallel(new Node()
86  //                        // parallel because we don't know which model
87  //                        .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MULE_SYSTEM_MODEL)
88  //                                .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MULE_SYSTEM_MODEL)))
89  //                        .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MODEL)
90  //                                .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MODEL)))
91  //                        .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING))
92  //                        .serial(new Node()
93  //                                // parallel because we don't know which model
94  //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MODEL)
95  //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MODEL)))
96  //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MULE_SYSTEM_MODEL)
97  //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL))))
98  //                        .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED))
99  //                        .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING))
100 //                        .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING))
101 //                        .serial(new Node()
102 //                                // parallel because we don't know which model
103 //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MODEL)
104 //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MODEL)))
105 //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MULE_SYSTEM_MODEL)
106 //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MULE_SYSTEM_MODEL))))
107 //                        .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED)
108 //                                // parallel because we don't know which model
109 //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MODEL)
110 //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MODEL)))
111 //                                .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MULE_SYSTEM_MODEL)
112 //                                        .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MULE_SYSTEM_MODEL))))
113 //                          .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED)));
114 //    }
115 
116     public void validateSpecification(RestrictedNode spec) throws Exception
117     {
118         verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_INITIALISED);
119         verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_STARTED);
120         verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_STOPPED);
121         verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_DISPOSED);
122     }
123 
124 }