View Javadoc

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