View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.messaging;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.junit.Test;
22  import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
23  import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocatorImpl;
24  import org.kuali.rice.ksb.messaging.remotedservices.GenericTestService;
25  import org.kuali.rice.ksb.messaging.remotedservices.TestServiceInterface;
26  import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
27  import org.kuali.rice.ksb.messaging.serviceconnectors.BusLocalConnector;
28  import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector;
29  import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnectorFactory;
30  import org.kuali.rice.ksb.service.KSBServiceLocator;
31  import org.kuali.rice.ksb.test.KSBTestCase;
32  
33  
34  /**
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class DevModeTest extends KSBTestCase {
39  
40  	@Override
41  	public void setUp() throws Exception {
42  		System.setProperty("dev.mode", "true");
43  		// included in ksb-test-config.xml
44  		System.setProperty("additional.config.locations", "classpath:org/kuali/rice/ksb/messaging/dev_mode_config.xml");
45  		super.setUp();
46  	}
47  
48  
49  
50  	@Override
51  	public void tearDown() throws Exception {
52  	    try {
53  		System.clearProperty("dev.mode");
54  	    // included in ksb-test-config.xml
55  		System.clearProperty("additional.config.locations");
56  	    } finally {
57  		super.tearDown();
58  	    }
59  	}
60  
61  
62  
63  	@Test public void testCallInDevMode() throws Exception {
64  		QName serviceName = new QName("KEW", "testLocalServiceFavoriteCall");
65  		TestServiceInterface service = (TestServiceInterface) GlobalResourceLoader.getService(serviceName);
66  		service.invoke();
67  		assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 0);
68  
69  		RemoteResourceServiceLocatorImpl rrsl = (RemoteResourceServiceLocatorImpl)KSBResourceLoaderFactory.getRemoteResourceLocator();
70  
71  		ServiceConnector serviceConnector = ServiceConnectorFactory.getServiceConnector(rrsl.getAllServices(serviceName).get(0).getServiceInfo());
72  		assertTrue("Not BusLocalConnector", serviceConnector instanceof BusLocalConnector);
73  		assertNull("Service in service definition needs to be null for async communications serialization", ((BusLocalConnector)serviceConnector).getServiceInfo().getServiceDefinition().getService());
74  
75  		service = (TestServiceInterface) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
76  		service.invoke();
77  		assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 1);
78  
79  		assertTrue("should be no registered services", KSBServiceLocator.getServiceRegistry().fetchAll().size() == 0);
80  	}
81  }