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.kew.rule; 017 018import static org.junit.Assert.assertEquals; 019import static org.junit.Assert.assertNotNull; 020import static org.junit.Assert.assertTrue; 021 022import javax.xml.namespace.QName; 023 024import org.junit.Test; 025import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 026import org.kuali.rice.kew.api.KewApiConstants; 027import org.kuali.rice.kew.api.WorkflowDocument; 028import org.kuali.rice.kew.api.WorkflowDocumentFactory; 029import org.kuali.rice.kew.api.exception.WorkflowException; 030import org.kuali.rice.kew.test.FakeService; 031import org.kuali.rice.kew.test.FakeServiceImpl.Invocation; 032import org.kuali.rice.kew.test.KEWTestCase; 033 034 035/** 036 * Tests that a groovy expression in a rule can invoke an arbitrary service on the KSB 037 * @author Kuali Rice Team (rice.collab@kuali.org) 038 */ 039public class ServiceInvocationRuleTest extends KEWTestCase { 040 protected void loadTestData() throws Exception { 041 loadXmlFile("ServiceInvokingRule.xml"); 042 } 043 044 @Test public void testServiceInvokingRule() throws WorkflowException { 045 // test that we can get the service to start with 046 FakeService fakeService = (FakeService) GlobalResourceLoader.getService(new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "fakeService-remote")); 047 assertNotNull(fakeService); 048 049 050 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("arh14"), "ServiceInvocationRuleTest"); 051 doc.route("routing"); 052 053 // no requests whatsoever were sent...we're done 054 assertTrue(doc.isFinal()); 055 056 fakeService = (FakeService) GlobalResourceLoader.getService(new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "fakeService-remote")); 057 058 assertEquals(1, fakeService.getInvocations().size()); 059 Invocation invocation = fakeService.getInvocations().get(0); 060 assertEquals("method2", invocation.methodName); 061 } 062}