01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.db;
18:
19: import java.util.Properties;
20:
21: import junit.framework.TestCase;
22:
23: import org.apache.commons.dbcp.BasicDataSource;
24: import org.bpmscript.IProcessManager;
25: import org.hibernate.SessionFactory;
26: import org.springframework.aop.framework.ProxyFactoryBean;
27: import org.springframework.jdbc.support.lob.DefaultLobHandler;
28: import org.springframework.orm.hibernate3.HibernateInterceptor;
29: import org.springframework.orm.hibernate3.HibernateTransactionManager;
30: import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
31: import org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource;
32: import org.springframework.transaction.interceptor.TransactionInterceptor;
33:
34: public class HibernateProcessManagerTest extends TestCase {
35:
36: protected void setUp() throws Exception {
37: super .setUp();
38: }
39:
40: protected void tearDown() throws Exception {
41: super .tearDown();
42: }
43:
44: public void testTheWholeShebang() throws Exception {
45:
46: BasicDataSource dataSource = new BasicDataSource();
47: dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
48: dataSource.setUrl("jdbc:hsqldb:mem:simulator");
49: dataSource.setUsername("sa");
50:
51: Properties properties = new Properties();
52: properties.setProperty("hibernate.hbm2ddl.auto", "update");
53: properties.setProperty("hibernate.dialect",
54: "org.hibernate.dialect.HSQLDialect");
55: properties.setProperty("hibernate.query.substitutions",
56: "true 1, false 0");
57: properties.setProperty("hibernate.show_sql", "false");
58:
59: LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
60: sessionFactoryBean.setLobHandler(new DefaultLobHandler());
61: sessionFactoryBean.setHibernateProperties(properties);
62: sessionFactoryBean.setMappingResources(new String[] {
63: "/org/bpmscript/db/DbProcess.hbm.xml",
64: "/org/bpmscript/db/DbProcessSource.hbm.xml",
65: "/org/bpmscript/db/DbProcessInstance.hbm.xml",
66: "/org/bpmscript/db/DbProcessInstanceState.hbm.xml" });
67: sessionFactoryBean.setDataSource(dataSource);
68: sessionFactoryBean.afterPropertiesSet();
69:
70: SessionFactory sessionFactory = (SessionFactory) sessionFactoryBean
71: .getObject();
72: HibernateTransactionManager transactionManager = new HibernateTransactionManager();
73: transactionManager.setSessionFactory(sessionFactory);
74:
75: HibernateInterceptor hibernateInterceptor = new HibernateInterceptor();
76: hibernateInterceptor.setSessionFactory(sessionFactory);
77:
78: TransactionInterceptor transactionInterceptor = new TransactionInterceptor();
79: transactionInterceptor
80: .setTransactionManager(transactionManager);
81: transactionInterceptor
82: .setTransactionAttributeSource(new MatchAlwaysTransactionAttributeSource());
83:
84: HibernateProcessManager processManagerTarget = new HibernateProcessManager();
85: processManagerTarget.setSessionFactory(sessionFactory);
86:
87: ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
88: proxyFactoryBean
89: .setProxyInterfaces(new Class[] { IProcessManager.class });
90: proxyFactoryBean.addAdvice(hibernateInterceptor);
91: proxyFactoryBean.addAdvice(transactionInterceptor);
92: proxyFactoryBean.setTarget(processManagerTarget);
93: IProcessManager processManager = (IProcessManager) proxyFactoryBean
94: .getObject();
95: String id = processManager.createProcess("bob", "bob", false);
96: assertNotNull(id);
97: }
98:
99: }
|