1   /*
2    * $Id: JBpmFunctionalTestCase.java 11580 2008-04-15 22:04:09Z tcarlson $
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.example.loanbroker.bpm;
12  
13  import org.mule.api.config.ConfigurationException;
14  import org.mule.config.i18n.MessageFactory;
15  import org.mule.example.loanbroker.tests.AbstractAsynchronousLoanBrokerTestCase;
16  import org.mule.transport.bpm.BPMS;
17  import org.mule.transport.bpm.ProcessConnector;
18  import org.mule.transport.jdbc.util.MuleDerbyUtils;
19  
20  
21  public class JBpmFunctionalTestCase extends AbstractAsynchronousLoanBrokerTestCase
22  {
23      /** For unit tests, we assume a virgin database, therefore the process ID is assumed to be = 1 */
24      public static final long PROCESS_ID = 1;
25  
26      public JBpmFunctionalTestCase()
27      {
28          super();
29          setDisposeManagerPerSuite(true);        
30      }
31      
32      @Override
33      protected void suitePreSetUp() throws Exception
34      {
35          // set the derby.system.home system property to make sure that all derby databases are
36          // created in maven's target directory
37          
38          MuleDerbyUtils.defaultDerbyCleanAndInit("derby.properties", "database.name");
39  
40          super.suitePreSetUp();
41      }
42  
43      @Override
44      protected String getConfigResources()
45      {
46          return "loan-broker-bpm-mule-config.xml";
47      }
48  
49      @Override
50      public void testSingleLoanRequest() throws Exception
51      {        
52          super.testSingleLoanRequest();
53          
54          ProcessConnector connector =
55              (ProcessConnector) muleContext.getRegistry().lookupConnector("jBpmConnector");
56          if (connector == null)
57          {
58              throw new ConfigurationException(MessageFactory.createStaticMessage("Unable to look up jBpmConnector from Mule registry."));
59          }
60          BPMS bpms = connector.getBpms();
61          // TODO MULE-1558 The following assert is throwing a 
62          //   org.hibernate.LazyInitializationException: could not initialize proxy - the owning MuleSession was closed
63          // See http://forum.springframework.org/archive/index.php/t-24800.html
64          //assertEquals("loanApproved", bpms.getState(bpms.lookupProcess(new Long(PROCESS_ID))));
65      }
66      
67      @Override
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  }