01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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 edu.iu.uis.eden.messaging;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.junit.Test;
21: import org.kuali.bus.services.KSBServiceLocator;
22: import org.kuali.bus.test.KSBTestCase;
23:
24: import edu.iu.uis.eden.messaging.callbacks.SimpleCallback;
25: import edu.iu.uis.eden.messaging.remotedservices.ServiceCallInformationHolder;
26: import edu.iu.uis.eden.messaging.resourceloading.KSBResourceLoaderFactory;
27:
28: /**
29: * simple test verifying if distributed topics are working.
30: *
31: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
32: *
33: */
34: public class DistributedTopicTest extends KSBTestCase {
35:
36: public boolean startClient1() {
37: return true;
38: }
39:
40: @Test
41: public void testSuccessfullyCallingSyncTopics() throws Exception {
42:
43: ((Runnable) KSBResourceLoaderFactory.getRemoteResourceLocator())
44: .run();
45: QName serviceName = new QName("testAppsSharedTopic",
46: "sharedTopic");
47:
48: KEWJavaService testJavaAsyncService = (KEWJavaService) KSBServiceLocator
49: .getMessageHelper().getServiceAsynchronously(
50: serviceName);
51: testJavaAsyncService
52: .invoke(new ClientAppServiceSharedPayloadObj(
53: "message content", false));
54:
55: assertTrue("Test harness topic never called",
56: ((Boolean) ServiceCallInformationHolder.stuff
57: .get("TestHarnessCalled")).booleanValue());
58: assertTrue("Cliet1 app topic never called",
59: ((Boolean) ServiceCallInformationHolder.stuff
60: .get("Client1Called")).booleanValue());
61: }
62:
63: @Test
64: public void testCallingAsyncTopics() throws Exception {
65: KSBTestUtils.setMessagingToAsync();
66:
67: QName serviceName = new QName("testAppsSharedTopic",
68: "sharedTopic");
69:
70: SimpleCallback simpleCallback = new SimpleCallback();
71: KEWJavaService testJavaAsyncService = (KEWJavaService) KSBServiceLocator
72: .getMessageHelper().getServiceAsynchronously(
73: serviceName, simpleCallback);
74: testJavaAsyncService
75: .invoke(new ClientAppServiceSharedPayloadObj(
76: "message content", false));
77: simpleCallback.waitForAsyncCall();
78: //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
79: //to determine if the client1 has been called.
80:
81: int i = 0;
82: while (i < 100) {
83: if (ServiceCallInformationHolder.stuff.get("Client1Called") != null) {
84: break;
85: }
86: Thread.sleep(1000);
87: i++;
88: }
89:
90: assertTrue("Test harness topic never called",
91: ((Boolean) ServiceCallInformationHolder.stuff
92: .get("TestHarnessCalled")).booleanValue());
93: assertTrue("Cliet1 app topic never called",
94: ((Boolean) ServiceCallInformationHolder.stuff
95: .get("Client1Called")).booleanValue());
96:
97: }
98:
99: }
|