View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
5    * compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.opensource.org/licenses/ecl2.php
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
10   * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
11   * language governing permissions and limitations under the License.
12   */
13  package org.kuali.rice.ksb.messaging;
14  
15  import javax.xml.namespace.QName;
16  
17  import org.junit.Test;
18  import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
19  import org.kuali.rice.ksb.messaging.service.KSBJavaService;
20  import org.kuali.rice.ksb.service.KSBServiceLocator;
21  import org.kuali.rice.ksb.test.KSBTestCase;
22  
23  
24  /**
25   * Test that a context object passed through messaging is preserved in
26   * 
27   * async queue async topic
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   * 
31   */
32  public class ContextObjectMessagingTest extends KSBTestCase {
33  
34      public boolean startClient1() {
35  	return true;
36      }
37  
38      @Test
39      public void testCallingQueueAsnyc() throws Exception {
40  	
41  	KSBTestUtils.setMessagingToAsync();
42  	QName serviceName = new QName("testAppsSharedQueue", "sharedQueue");
43  	String contextObject = "my_context_object";
44  	SimpleCallback callback = new SimpleCallback();
45  	
46  		KSBJavaService testJavaAsyncService = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject);
47  	    
48  	synchronized (callback) {
49  	    testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
50  	    callback.waitForAsyncCall();
51  	}
52  
53  	Object contextAfterMessaging = callback.getMethodCall().getContext();
54  	assertEquals(contextObject, contextAfterMessaging);
55      }
56  
57      @Test
58      public void testCallingAsyncTopics() throws Exception {
59  	KSBTestUtils.setMessagingToAsync();
60  	QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
61  
62  	SimpleCallback callback = new SimpleCallback();
63  	String contextObject = "my_context_object";
64  		KSBJavaService testJavaAsyncService = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject);
65  	
66  	synchronized (callback) {
67  	    testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
68  	    callback.waitForAsyncCall();    
69  	}
70  	
71  	Object contextAfterMessaging = callback.getMethodCall().getContext();
72  	assertEquals(contextObject, contextAfterMessaging);
73      }
74  
75  }