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.kew.rule;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.junit.Test;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.kew.api.KewApiConstants;
27  import org.kuali.rice.kew.api.WorkflowDocument;
28  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
29  import org.kuali.rice.kew.api.exception.WorkflowException;
30  import org.kuali.rice.kew.test.FakeService;
31  import org.kuali.rice.kew.test.FakeServiceImpl.Invocation;
32  import org.kuali.rice.kew.test.KEWTestCase;
33  
34  
35  /**
36   * Tests that a groovy expression in a rule can invoke an arbitrary service on the KSB 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class ServiceInvocationRuleTest extends KEWTestCase {
40      protected void loadTestData() throws Exception {
41          loadXmlFile("ServiceInvokingRule.xml");
42      }
43  
44      @Test public void testServiceInvokingRule() throws WorkflowException {
45          // test that we can get the service to start with
46          FakeService fakeService = (FakeService) GlobalResourceLoader.getService(new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "fakeService-remote"));
47          assertNotNull(fakeService);
48          
49          
50          WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("arh14"), "ServiceInvocationRuleTest");
51          doc.route("routing");
52  
53          // no requests whatsoever were sent...we're done
54          assertTrue(doc.isFinal());
55          
56          fakeService = (FakeService) GlobalResourceLoader.getService(new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "fakeService-remote"));
57          
58          assertEquals(1, fakeService.getInvocations().size());
59          Invocation invocation = fakeService.getInvocations().get(0);
60          assertEquals("method2", invocation.methodName);
61      }
62  }