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.context.notification; 8 9 import org.mule.api.service.Service; 10 import org.mule.module.client.MuleClient; 11 12 import static org.junit.Assert.assertNotNull; 13 14 public class ServerNotificationManagerTestCase extends AbstractNotificationTestCase 15 { 16 17 public static final String MULE_SYSTEM_MODEL = "_muleSystemModel"; 18 public static final String MODEL = "the-model"; 19 public static final String SERVICE = "the-service"; 20 21 @Override 22 protected String getConfigResources() 23 { 24 return "org/mule/test/integration/notifications/server-notification-manager-test.xml"; 25 } 26 27 @Override 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 @Override 38 public RestrictedNode getSpecification() 39 { 40 return new Node() 41 // all service events are asynchronous, so place parallel to rest 42 .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_INITIALISED, SERVICE)) 43 .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STARTED, SERVICE)) 44 .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_PAUSED, SERVICE)) 45 .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_RESUMED, 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 .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MULE_SYSTEM_MODEL)) 52 .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MODEL)) 53 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING)) 54 .serial(new Node() 55 // parallel because we don't know which model 56 .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MODEL)) 57 .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL)) 58 .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL))) 59 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED)) 60 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING)) 61 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING)) 62 .serial(new Node() 63 // parallel because we don't know which model 64 .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MULE_SYSTEM_MODEL)) 65 .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MODEL))) 66 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED) 67 // parallel because we don't know which model 68 .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MODEL)) 69 .parallel(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MULE_SYSTEM_MODEL))) 70 .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED))); 71 } 72 73 //Before 74 // public RestrictedNode getSpecificationx() 75 // { 76 // return new Node() 77 // // all service events are asynchronous, so place parallel to rest 78 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_INITIALISED, SERVICE)) 79 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STARTED, SERVICE)) 80 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_PAUSED, SERVICE)) 81 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_RESUMED, SERVICE)) 82 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPED, SERVICE)) 83 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_STOPPED, SERVICE)) 84 // .parallel(new Node(ServiceNotification.class, ServiceNotification.SERVICE_DISPOSED, SERVICE)) 85 // // synchronous events start here 86 // .parallel(new Node() 87 // // parallel because we don't know which model 88 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MULE_SYSTEM_MODEL) 89 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MULE_SYSTEM_MODEL))) 90 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISING, MODEL) 91 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_INITIALISED, MODEL))) 92 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTING)) 93 // .serial(new Node() 94 // // parallel because we don't know which model 95 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MODEL) 96 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MODEL))) 97 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STARTING, MULE_SYSTEM_MODEL) 98 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STARTED, MULE_SYSTEM_MODEL)))) 99 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STARTED)) 100 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSING)) 101 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPING)) 102 // .serial(new Node() 103 // // parallel because we don't know which model 104 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MODEL) 105 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MODEL))) 106 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPING, MULE_SYSTEM_MODEL) 107 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_STOPPED, MULE_SYSTEM_MODEL)))) 108 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_STOPPED) 109 // // parallel because we don't know which model 110 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MODEL) 111 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MODEL))) 112 // .parallelSynch(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSING, MULE_SYSTEM_MODEL) 113 // .serial(new Node(ModelNotification.class, ModelNotification.MODEL_DISPOSED, MULE_SYSTEM_MODEL)))) 114 // .serial(new Node(MuleContextNotification.class, MuleContextNotification.CONTEXT_DISPOSED))); 115 // } 116 117 @Override 118 public void validateSpecification(RestrictedNode spec) throws Exception 119 { 120 verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_INITIALISED); 121 verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_STARTED); 122 verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_STOPPED); 123 verifyNotification(spec, ModelNotification.class, ModelNotification.MODEL_DISPOSED); 124 } 125 126 }