/* * Copyright 2007, Bill Middleton * With significant borrowage from one or more jboss jbpm test scripts. * * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ import junit.framework.TestCase; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.identity.Entity; import org.jbpm.identity.hibernate.IdentitySession; import org.jbpm.identity.xml.IdentityXmlParser; import org.jbpm.persistence.db.DbPersistenceServiceFactory; import org.jbpm.svc.Services; /** * A simple junit testcase which will create and populate the jbpm database * schema, including identity tables, for _any_ given database * which is supported by hibernate. This tool also installs the default * test users (ernie, bert, grover, cookie monster) in the db, so that the * jbpm-console can be deployed and run under any given server including * tomcat, jetty, etc, using a simple JdbcUserRealm based upon the jbpm * entities. * * Included with this testcase should be an sesamestreet.xml file containing * all of the user, group, and membership info, as well as a hibernate.cfg.xml * file which is configured for postgres, but may be easily changed to whatever * DB/dialect is desired. If you use your own hibernate.cfg.xml, be sure to * add the mappings for jbpm identity tables before you run this test. * * @author Bill Middleton * */ public class dbCreate extends TestCase { JbpmConfiguration jc = null; DbPersistenceServiceFactory dbp = null; JbpmContext jcxt; public void setUp() { /* * A hibernate.cfg.xml including the mappings for identity (User, Group, Membership) * must be found in the classpath. */ jc = JbpmConfiguration.getInstance(); dbp = (DbPersistenceServiceFactory) jc.getServiceFactory(Services.SERVICENAME_PERSISTENCE); dbp.createSchema(); } public void tearDown() { // Ordinarily, we'd drop the schema here, but we want it to remain // since the purpose of this thing is to initialize the database // and populate it with the test users. // So we exit without doing a thing. // dbp.dropSchema(); } /** * Install all of the test users (ernie, bert, etc) from sesamestreet.xml */ public void testLoadIdentities() { jcxt = jc.createJbpmContext(); try { Entity[] et = IdentityXmlParser.parseEntitiesResource("sesamestreet.xml"); IdentitySession id = new IdentitySession(jcxt.getSession()); for (int i = 0; i < et.length; i++) { id.saveEntity(et[i]); } } finally { jcxt.close(); } } }