1   /*
2    * $Id: JBpmFunctionalTestCase.java 9493 2007-10-31 02:03:22Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.examples.loanbroker.bpm;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.ConfigurationBuilder;
15  import org.mule.config.ConfigurationException;
16  import org.mule.config.i18n.MessageFactory;
17  import org.mule.examples.loanbroker.tests.AbstractAsynchronousLoanBrokerTestCase;
18  import org.mule.extras.spring.config.SpringConfigurationBuilder;
19  import org.mule.providers.bpm.BPMS;
20  import org.mule.providers.bpm.ProcessConnector;
21  import org.mule.providers.jdbc.util.MuleDerbyUtils;
22  
23  
24  public class JBpmFunctionalTestCase extends AbstractAsynchronousLoanBrokerTestCase
25  {
26      /** For unit tests, we assume a virgin database, therefore the process ID is assumed to be = 1 */
27      public static final long PROCESS_ID = 1;
28  
29      protected void suitePreSetUp() throws Exception
30      {
31          // set the derby.system.home system property to make sure that all derby databases are
32          // created in maven's target directory
33          
34          MuleDerbyUtils.defaultDerbyCleanAndInit("derby.properties", "database.name");
35  
36          super.suitePreSetUp();
37      }
38  
39      protected ConfigurationBuilder getBuilder() throws Exception 
40      {
41          return new SpringConfigurationBuilder();
42      }
43      
44      // @Override
45      protected String getConfigResources()
46      {
47          return "loan-broker-bpm-mule-config.xml";
48      }
49  
50      // @Override
51      public void testSingleLoanRequest() throws Exception
52      {
53          super.testSingleLoanRequest();
54          
55          ProcessConnector connector =
56              (ProcessConnector) MuleManager.getInstance().lookupConnector("jBpmConnector");
57          if (connector == null)
58          {
59              throw new ConfigurationException(MessageFactory.createStaticMessage("Unable to look up jBpmConnector from Mule registry."));
60          }
61          BPMS bpms = connector.getBpms();
62          // TODO MULE-1558 The following assert is throwing a 
63          //   org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
64          // See http://forum.springframework.org/archive/index.php/t-24800.html
65          //assertEquals("loanApproved", bpms.getState(bpms.lookupProcess(new Long(PROCESS_ID))));
66      }
67      
68      public void testLotsOfLoanRequests() throws Exception
69      {
70          super.testLotsOfLoanRequests();
71          
72          //without this sleep, the test still succeeds but throws a series of exceptions
73          //probably Spring would not have enough time to close db connections before
74          //database itself is shut down while jvm start disposing
75          Thread.sleep(100);
76      }
77  }