View Javadoc

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