001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.messaging;
017
018 import static org.junit.Assert.assertTrue;
019
020 import javax.xml.namespace.QName;
021
022 import org.junit.Test;
023 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
024 import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
025 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
026 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
027 import org.kuali.rice.ksb.test.KSBTestCase;
028
029
030 /**
031 * simple test verifying if distributed topics are working.
032 *
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 *
035 */
036 public class DistributedTopicTest extends KSBTestCase {
037
038 public boolean startClient1() {
039 return true;
040 }
041
042 @Test
043 public void testSuccessfullyCallingSyncTopics() throws Exception {
044
045 KsbApiServiceLocator.getServiceBus().synchronize();
046 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
047
048 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
049 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
050
051 assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
052 assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("Client1Called")).booleanValue());
053 }
054
055 @Test public void testCallingAsyncTopics() throws Exception {
056 KSBTestUtils.setMessagingToAsync();
057
058 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
059
060 SimpleCallback simpleCallback = new SimpleCallback();
061 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, simpleCallback);
062 synchronized (simpleCallback) {
063 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
064 simpleCallback.waitForAsyncCall();
065 }
066 //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
067 //to determine if the client1 has been called.
068
069 int i = 0;
070 while (i < 100) {
071 if (ServiceCallInformationHolder.stuff.get("Client1Called") != null) {
072 break;
073 }
074 Thread.sleep(1000);
075 i++;
076 }
077
078 assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
079 assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("Client1Called")).booleanValue());
080
081 }
082
083 }