View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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 org.kuali.rice.ksb.messaging;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  import javax.xml.namespace.QName;
21  
22  import junit.framework.Assert;
23  
24  import org.junit.Test;
25  import org.kuali.rice.core.api.config.property.ConfigContext;
26  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
27  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
28  import org.kuali.rice.ksb.api.bus.ServiceBus;
29  import org.kuali.rice.ksb.messaging.remotedservices.GenericTestService;
30  import org.kuali.rice.ksb.messaging.remotedservices.TestServiceInterface;
31  import org.kuali.rice.ksb.messaging.serviceconnectors.BusLocalConnector;
32  import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector;
33  import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnectorFactory;
34  import org.kuali.rice.ksb.test.KSBTestCase;
35  
36  /**
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  public class DevModeTest extends KSBTestCase {
41  
42      @Override
43  	public void setUp() throws Exception {
44  		// included in ksb-test-config.xml
45  		System.setProperty("a.test.specific.config.location", "classpath:org/kuali/rice/ksb/messaging/dev_mode_config.xml");
46  		super.setUp();
47  	}
48  
49  	@Override
50  	public void tearDown() throws Exception {
51  	    try {
52  	        // included in ksb-test-config.xml
53              System.clearProperty("a.test.specific.config.location");
54  	    } finally {
55  		    super.tearDown();
56  	    }
57  	}
58  
59  	@Test public void testCallInDevMode() throws Exception {
60          //make sure we are actually in dev mode
61  		Assert.assertEquals(ConfigContext.getCurrentContextConfig().getDevMode(), Boolean.TRUE);
62  
63          QName serviceName = new QName("KEW", "testLocalServiceFavoriteCall");
64  		TestServiceInterface service = (TestServiceInterface) GlobalResourceLoader.getService(serviceName);
65  		service.invoke();
66  		assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 0);
67  
68  		ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
69  
70  		ServiceConnector serviceConnector = ServiceConnectorFactory.getServiceConnector(serviceBus.getLocalEndpoint(serviceName).getServiceConfiguration());
71  		assertTrue("Not BusLocalConnector", serviceConnector instanceof BusLocalConnector);
72  		//assertNull("Service in service definition needs to be null for async communications serialization", ((BusLocalConnector)serviceConnector).getServiceConfiguration()().getServiceDefinition().getService());
73  
74  		service = (TestServiceInterface) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
75  		service.invoke();
76  		assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 1);
77  
78  		Assert.assertEquals("should be no registered services", KsbApiServiceLocator.getServiceRegistry().getAllServices().size(), 0);
79  	}
80  }