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