001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.ksb.messaging; 017 018import org.junit.Test; 019import org.kuali.rice.ksb.api.KsbApiServiceLocator; 020import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback; 021import org.kuali.rice.ksb.messaging.service.KSBJavaService; 022import org.kuali.rice.ksb.test.KSBTestCase; 023 024import javax.xml.namespace.QName; 025 026import static org.junit.Assert.assertEquals; 027 028 029/** 030 * Test that a context object passed through messaging is preserved in 031 * 032 * async queue async topic 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 * 036 */ 037public class ContextObjectMessagingTest extends KSBTestCase { 038 039 public boolean startClient1() { 040 return true; 041 } 042 043 @Test 044 public void testCallingQueueAsnyc() throws Exception { 045 046 KSBTestUtils.setMessagingToAsync(); 047 QName serviceName = new QName("testAppsSharedQueue", "sharedQueue"); 048 String contextObject = "my_context_object"; 049 SimpleCallback callback = new SimpleCallback(); 050 051 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject); 052 053 synchronized (callback) { 054 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false)); 055 callback.waitForAsyncCall(); 056 } 057 058 Object contextAfterMessaging = callback.getMethodCall().getContext(); 059 assertEquals(contextObject, contextAfterMessaging); 060 } 061 062 @Test 063 public void testCallingAsyncTopics() throws Exception { 064 KSBTestUtils.setMessagingToAsync(); 065 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic"); 066 067 SimpleCallback callback = new SimpleCallback(); 068 String contextObject = "my_context_object"; 069 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject); 070 071 synchronized (callback) { 072 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false)); 073 callback.waitForAsyncCall(); 074 } 075 076 Object contextAfterMessaging = callback.getMethodCall().getContext(); 077 assertEquals(contextObject, contextAfterMessaging); 078 } 079 080}