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     */
016    package org.kuali.rice.ksb.messaging;
017    
018    import static org.junit.Assert.assertTrue;
019    
020    import javax.xml.namespace.QName;
021    
022    import junit.framework.Assert;
023    
024    import org.junit.Test;
025    import org.kuali.rice.core.api.config.property.ConfigContext;
026    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
027    import org.kuali.rice.ksb.api.KsbApiServiceLocator;
028    import org.kuali.rice.ksb.api.bus.ServiceBus;
029    import org.kuali.rice.ksb.messaging.remotedservices.GenericTestService;
030    import org.kuali.rice.ksb.messaging.remotedservices.TestServiceInterface;
031    import org.kuali.rice.ksb.messaging.serviceconnectors.BusLocalConnector;
032    import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector;
033    import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnectorFactory;
034    import org.kuali.rice.ksb.test.KSBTestCase;
035    
036    /**
037     *
038     * @author Kuali Rice Team (rice.collab@kuali.org)
039     */
040    public class DevModeTest extends KSBTestCase {
041    
042        @Override
043            public void setUp() throws Exception {
044                    // included in ksb-test-config.xml
045                    System.setProperty("a.test.specific.config.location", "classpath:org/kuali/rice/ksb/messaging/dev_mode_config.xml");
046                    super.setUp();
047            }
048    
049            @Override
050            public void tearDown() throws Exception {
051                try {
052                    // included in ksb-test-config.xml
053                System.clearProperty("a.test.specific.config.location");
054                } finally {
055                        super.tearDown();
056                }
057            }
058    
059            @Test public void testCallInDevMode() throws Exception {
060            //make sure we are actually in dev mode
061                    Assert.assertEquals(ConfigContext.getCurrentContextConfig().getDevMode(), Boolean.TRUE);
062    
063            QName serviceName = new QName("KEW", "testLocalServiceFavoriteCall");
064                    TestServiceInterface service = (TestServiceInterface) GlobalResourceLoader.getService(serviceName);
065                    service.invoke();
066                    assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 0);
067    
068                    ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
069    
070                    ServiceConnector serviceConnector = ServiceConnectorFactory.getServiceConnector(serviceBus.getLocalEndpoint(serviceName).getServiceConfiguration());
071                    assertTrue("Not BusLocalConnector", serviceConnector instanceof BusLocalConnector);
072                    //assertNull("Service in service definition needs to be null for async communications serialization", ((BusLocalConnector)serviceConnector).getServiceConfiguration()().getServiceDefinition().getService());
073    
074                    service = (TestServiceInterface) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
075                    service.invoke();
076                    assertTrue("No calls to dev defined service", GenericTestService.NUM_CALLS > 1);
077    
078                    Assert.assertEquals("should be no registered services", KsbApiServiceLocator.getServiceRegistry().getAllServices().size(), 0);
079            }
080    }