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 static org.junit.Assert.assertTrue;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.junit.Test;
23  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
24  import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
25  import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
26  import org.kuali.rice.ksb.messaging.service.KSBJavaService;
27  import org.kuali.rice.ksb.test.KSBTestCase;
28  
29  
30  /**
31   * simple test verifying if distributed topics are working.
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class DistributedTopicTest extends KSBTestCase {
37  	
38  	public boolean startClient1() {
39  		return true;
40  	}
41  	
42  	@Test
43  	public void testSuccessfullyCallingSyncTopics() throws Exception {
44  		
45  		KsbApiServiceLocator.getServiceBus().synchronize();
46  		QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
47  		
48  		KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
49  		testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
50  		
51  		assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
52  		assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("Client1Called")).booleanValue());
53  	}
54  	
55  	@Test public void testCallingAsyncTopics() throws Exception {
56  	    	KSBTestUtils.setMessagingToAsync();
57  		
58  		QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
59  		
60  		SimpleCallback simpleCallback = new SimpleCallback();
61  		KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, simpleCallback);
62  		synchronized (simpleCallback) {
63  		    testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
64  		    simpleCallback.waitForAsyncCall();
65  		}
66  		//because topic invocation doesn't happen in the message service invoker like it should this wait is really on half the answer.  We need to wait long and poll 
67  		//to determine if the client1 has been called.
68  		
69  		int i = 0;
70  		while (i < 100) {
71  		    if (ServiceCallInformationHolder.stuff.get("Client1Called") != null) {
72  			break;
73  		    }
74  		    Thread.sleep(1000);
75  		    i++;
76  		}
77  	
78  		assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
79  		assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("Client1Called")).booleanValue());
80  	
81  	}
82  	
83  }