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 java.util.List;
19:
20: import javax.xml.namespace.QName;
21:
22: import org.junit.Test;
23: import org.kuali.bus.services.KSBServiceLocator;
24: import org.kuali.bus.test.KSBTestCase;
25: import org.kuali.rice.config.Config;
26: import org.kuali.rice.core.Core;
27:
28: import edu.iu.uis.eden.messaging.bam.BAMService;
29: import edu.iu.uis.eden.messaging.bam.BAMTargetEntry;
30: import edu.iu.uis.eden.messaging.callbacks.SimpleCallback;
31: import edu.iu.uis.eden.messaging.resourceloading.KSBResourceLoaderFactory;
32:
33: /**
34: * Tests calling services in a very simple scenario. This test could probably go
35: * now that more 'feature-full' tests are out there.
36: *
37: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
38: *
39: */
40: public class SimpleServiceCallTest extends KSBTestCase {
41:
42: public boolean startClient1() {
43: return true;
44: }
45:
46: @Test
47: public void testAsyncJavaCall() throws Exception {
48: KSBTestUtils.setMessagingToAsync();
49:
50: QName serviceName = new QName("TestCl1", "testJavaAsyncService");
51: SimpleCallback callback = new SimpleCallback();
52: KEWJavaService testJavaAsyncService = (KEWJavaService) KSBServiceLocator
53: .getMessageHelper().getServiceAsynchronously(
54: serviceName, callback);
55: testJavaAsyncService.invoke(new MessagingTestObject(
56: "message content"));
57: callback.waitForAsyncCall();
58: verifyServiceCalls(serviceName);
59: }
60:
61: @Test
62: public void testAsyncXmlCall() throws Exception {
63: KSBTestUtils.setMessagingToAsync();
64:
65: QName serviceName = new QName("TestCl1", "testXmlAsyncService");
66: SimpleCallback callback = new SimpleCallback();
67: KEWXMLService testXmlAsyncService = (KEWXMLService) KSBServiceLocator
68: .getMessageHelper().getServiceAsynchronously(
69: serviceName, callback);
70: testXmlAsyncService.invoke("message content");
71: callback.waitForAsyncCall();
72: verifyServiceCalls(serviceName);
73: }
74:
75: private void verifyServiceCalls(QName serviceName) throws Exception {
76: BAMService bamService = KSBServiceLocator.getBAMService();
77: List<BAMTargetEntry> bamCalls = bamService
78: .getCallsForService(serviceName);
79: assertTrue("No service call recorded", bamCalls.size() > 0);
80: boolean foundClientCall = false;
81: boolean foundServiceCall = false;
82: for (BAMTargetEntry bamEntry : bamCalls) {
83: if (bamEntry.getServerInvocation()) {
84: foundServiceCall = true;
85: } else {
86: foundClientCall = true;
87: }
88: }
89: assertTrue("No client call recorded", foundClientCall);
90: assertTrue("No service call recorded", foundServiceCall);
91: }
92:
93: }
|