001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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 edu.iu.uis.eden.messaging;
017:
018: import java.util.List;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.junit.Test;
023: import org.kuali.bus.services.KSBServiceLocator;
024: import org.kuali.bus.test.KSBTestCase;
025:
026: import edu.iu.uis.eden.messaging.bam.BAMService;
027: import edu.iu.uis.eden.messaging.bam.BAMTargetEntry;
028: import edu.iu.uis.eden.messaging.callbacks.SimpleCallback;
029:
030: /**
031: * Tests distributed Queue scenarios
032: *
033: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
034: *
035: */
036: public class DistributedQueueTest extends KSBTestCase {
037:
038: public boolean startClient1() {
039: return true;
040: }
041:
042: public boolean startClient2() {
043: return true;
044: }
045:
046: /**
047: * If calling a queue with multiple subscribers only one subscriber should be calld.
048: *
049: * @throws Exception
050: */
051: @Test
052: public void testSuccessfullyCallingQueueOnce() throws Exception {
053:
054: QName serviceName = new QName("testAppsSharedQueue",
055: "sharedQueue");
056:
057: KEWJavaService testJavaAsyncService = (KEWJavaService) KSBServiceLocator
058: .getMessageHelper().getServiceAsynchronously(
059: serviceName);
060: testJavaAsyncService
061: .invoke(new ClientAppServiceSharedPayloadObj(
062: "message content", false));
063: verifyServiceCalls(serviceName);
064:
065: }
066:
067: @Test
068: public void testCallingQueueAsnyc() throws Exception {
069: KSBTestUtils.setMessagingToAsync();
070:
071: QName serviceName = new QName("testAppsSharedQueue",
072: "sharedQueue");
073: SimpleCallback callback = new SimpleCallback();
074: KEWJavaService testJavaAsyncService = (KEWJavaService) KSBServiceLocator
075: .getMessageHelper().getServiceAsynchronously(
076: serviceName, callback);
077: testJavaAsyncService
078: .invoke(new ClientAppServiceSharedPayloadObj(
079: "message content", false));
080: callback.waitForAsyncCall();
081: verifyServiceCalls(serviceName);
082: }
083:
084: private void verifyServiceCalls(QName serviceName) throws Exception {
085: BAMService bamService = KSBServiceLocator.getBAMService();
086: List<BAMTargetEntry> bamCalls = bamService
087: .getCallsForService(serviceName);
088: assertTrue("No service call recorded", bamCalls.size() > 0);
089: boolean foundClientCall = false;
090: boolean foundServiceCall = false;
091: for (BAMTargetEntry bamEntry : bamCalls) {
092: if (bamEntry.getServerInvocation()) {
093: foundServiceCall = true;
094: } else {
095: foundClientCall = true;
096: }
097: }
098: assertTrue("No client call recorded", foundClientCall);
099: assertTrue("No service call recorded", foundServiceCall);
100: assertEquals("Wrong number of calls recorded", 2, bamCalls
101: .size());
102: }
103:
104: }
|