// Path: src/main/java/junit/rules/jpa/hibernate/DerbyHibernateUtil.java
// public static final String JDBC_DERBY_URL = "jdbc:derby:test";
// 
// Path: src/main/java/junit/rules/util/Reflection.java
// public static MethodInvoker invoke(final Method method) {
//     return new MethodInvoker(method);
// }
// 
// Path: src/main/java/junit/rules/util/Reflection.java
// public static FieldWrapper set(final Field field) {
//     return new FieldWrapper(field);
// }
// 
// Path: src/main/java/junit/rules/dbunit/DbUnitUtil.java
// public final class DbUnitUtil {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(DbUnitUtil.class);
// 
//     /**
//      * Utility classes should not have a public or default constructor.
//      */
//     private DbUnitUtil() {
//         // noop
//     }
// 
//     /**
//      * @param fixtureNames
//      *        the fixture names
//      * @return IDataSet[]
//      */
//     public static IDataSet[] loadDataSets(final List<String> fixtureNames) {
//         final List<IDataSet> dataSets = new ArrayList<IDataSet>();
// 
//         for (final String fixtureName : fixtureNames) {
//             LOGGER.trace("Attempting to load database fixture \"" + fixtureName + "\"");
//             final IDataSet dataSet = attemptToLoadFixture(fixtureName);
//             if (dataSet != null) {
//                 dataSets.add(dataSet);
//             }
//         }
// 
//         return dataSets.toArray(new IDataSet[dataSets.size()]);
//     }
// 
//     /**
//      * @param fixtureName
//      *        the fixture name
//      * @return {@link IDataSet}
//      */
//     private static IDataSet attemptToLoadFixture(final String fixtureName) {
//         IDataSet dataSet = null;
// 
//         try {
//             final InputStream in = new FileInputStream(getFile(fixtureName));
//             try {
//                 if (in != null) {
//                     if (fixtureName.endsWith(".xml")) {
//                         dataSet = new XmlDataSet(in);
//                     }
//                 }
//             } finally {
//                 in.close();
//             }
//         } catch (final Exception e) {
//             throw new Error(e.getMessage(), e);
//         }
//         return dataSet;
//     }
// 
//     /**
//      * @param fixtureName
//      *        the fixture (file) name
//      * @return the {@link File} with the prefix
//      */
//     public static File getFile(final String fixtureName) {
//         return new File("src/test/db/fixtures", fixtureName);
//     }
// 
// }
// 
// Path: src/main/java/junit/rules/dbunit/FixturesUtil.java
// public final class FixturesUtil {
// 
//     /**
//      * Utility classes should not have a public or default constructor.
//      */
//     private FixturesUtil() {
//         // noop
//     }
// 
//     /**
//      * @param elements
//      *        the Class(es) or Method(s) to inspect for the {@link Fixtures} annotation
//      * @return the list of fixture names
//      */
//     public static List<String> getFixtureNames(final AnnotatedElement... elements) {
//         final List<String> fixtureNames = new ArrayList<String>();
//         for (final AnnotatedElement element : elements) {
//             if (element.isAnnotationPresent(Fixtures.class)) {
//                 for (final String fixtureName : element.getAnnotation(Fixtures.class).value()) {
//                     fixtureNames.add(fixtureName);
//                 }
//             }
//         }
//         return fixtureNames;
//     }
// 
// }


import static junit.rules.jpa.hibernate.DerbyHibernateUtil.JDBC_DERBY_URL;
import static junit.rules.util.Reflection.invoke;
import static junit.rules.util.Reflection.set;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import junit.rules.dbunit.DbUnitUtil;
import junit.rules.dbunit.FixturesUtil;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.dataset.CompositeDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.hibernate.ejb.Ejb3Configuration;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * junit-rules: JUnit Rules Library
 *
 * Copyright (c) 2009-2011 by Alistair A. Israel.
 * This software is made available under the terms of the MIT License.
 *
 * Created Oct 22, 2009
 */
package junit.rules.jpa.hibernate;






/**
 * @author Alistair A. Israel
 */
public class DerbyHibernateTestCase {

    private static final Logger logger = LoggerFactory.getLogger(HibernatePersistenceContext.class);

    private static final ThreadLocal<EntityManagerFactory> ENTITY_MANAGER_FACTORY = new ThreadLocal<EntityManagerFactory>();

    private EntityManager entityManager;

    private JdbcDatabaseTester jdbcDatabaseTester;

    /**
     *
     */
    @BeforeClass
    public static void initializeDerbyHibernate() {
        final Ejb3Configuration configuration = DerbyHibernateUtil.configureDerbyHibernateJpa();
        ENTITY_MANAGER_FACTORY.set(configuration.buildEntityManagerFactory());
    }

    /**
     *
     */
    @AfterClass
    public static void closeHibernateDerby() {
        ENTITY_MANAGER_FACTORY.get().close();
        try {
// Path: src/main/java/junit/rules/jpa/hibernate/DerbyHibernateUtil.java
// public static final String JDBC_DERBY_URL = "jdbc:derby:test";
// 
// Path: src/main/java/junit/rules/util/Reflection.java
// public static MethodInvoker invoke(final Method method) {
//     return new MethodInvoker(method);
// }
// 
// Path: src/main/java/junit/rules/util/Reflection.java
// public static FieldWrapper set(final Field field) {
//     return new FieldWrapper(field);
// }
// 
// Path: src/main/java/junit/rules/dbunit/DbUnitUtil.java
// public final class DbUnitUtil {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(DbUnitUtil.class);
// 
//     /**
//      * Utility classes should not have a public or default constructor.
//      */
//     private DbUnitUtil() {
//         // noop
//     }
// 
//     /**
//      * @param fixtureNames
//      *        the fixture names
//      * @return IDataSet[]
//      */
//     public static IDataSet[] loadDataSets(final List<String> fixtureNames) {
//         final List<IDataSet> dataSets = new ArrayList<IDataSet>();
// 
//         for (final String fixtureName : fixtureNames) {
//             LOGGER.trace("Attempting to load database fixture \"" + fixtureName + "\"");
//             final IDataSet dataSet = attemptToLoadFixture(fixtureName);
//             if (dataSet != null) {
//                 dataSets.add(dataSet);
//             }
//         }
// 
//         return dataSets.toArray(new IDataSet[dataSets.size()]);
//     }
// 
//     /**
//      * @param fixtureName
//      *        the fixture name
//      * @return {@link IDataSet}
//      */
//     private static IDataSet attemptToLoadFixture(final String fixtureName) {
//         IDataSet dataSet = null;
// 
//         try {
//             final InputStream in = new FileInputStream(getFile(fixtureName));
//             try {
//                 if (in != null) {
//                     if (fixtureName.endsWith(".xml")) {
//                         dataSet = new XmlDataSet(in);
//                     }
//                 }
//             } finally {
//                 in.close();
//             }
//         } catch (final Exception e) {
//             throw new Error(e.getMessage(), e);
//         }
//         return dataSet;
//     }
// 
//     /**
//      * @param fixtureName
//      *        the fixture (file) name
//      * @return the {@link File} with the prefix
//      */
//     public static File getFile(final String fixtureName) {
//         return new File("src/test/db/fixtures", fixtureName);
//     }
// 
// }
// 
// Path: src/main/java/junit/rules/dbunit/FixturesUtil.java
// public final class FixturesUtil {
// 
//     /**
//      * Utility classes should not have a public or default constructor.
//      */
//     private FixturesUtil() {
//         // noop
//     }
// 
//     /**
//      * @param elements
//      *        the Class(es) or Method(s) to inspect for the {@link Fixtures} annotation
//      * @return the list of fixture names
//      */
//     public static List<String> getFixtureNames(final AnnotatedElement... elements) {
//         final List<String> fixtureNames = new ArrayList<String>();
//         for (final AnnotatedElement element : elements) {
//             if (element.isAnnotationPresent(Fixtures.class)) {
//                 for (final String fixtureName : element.getAnnotation(Fixtures.class).value()) {
//                     fixtureNames.add(fixtureName);
//                 }
//             }
//         }
//         return fixtureNames;
//     }
// 
// }


// Path: src/main/java/junit/rules/jpa/hibernate/DerbyHibernateTestCase.java
import static junit.rules.jpa.hibernate.DerbyHibernateUtil.JDBC_DERBY_URL;
import static junit.rules.util.Reflection.invoke;
import static junit.rules.util.Reflection.set;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import junit.rules.dbunit.DbUnitUtil;
import junit.rules.dbunit.FixturesUtil;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.dataset.CompositeDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.hibernate.ejb.Ejb3Configuration;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * junit-rules: JUnit Rules Library
 *
 * Copyright (c) 2009-2011 by Alistair A. Israel.
 * This software is made available under the terms of the MIT License.
 *
 * Created Oct 22, 2009
 */
package junit.rules.jpa.hibernate;






/**
 * @author Alistair A. Israel
 */
public class DerbyHibernateTestCase {

    private static final Logger logger = LoggerFactory.getLogger(HibernatePersistenceContext.class);

    private static final ThreadLocal<EntityManagerFactory> ENTITY_MANAGER_FACTORY = new ThreadLocal<EntityManagerFactory>();

    private EntityManager entityManager;

    private JdbcDatabaseTester jdbcDatabaseTester;

    /**
     *
     */
    @BeforeClass
    public static void initializeDerbyHibernate() {
        final Ejb3Configuration configuration = DerbyHibernateUtil.configureDerbyHibernateJpa();
        ENTITY_MANAGER_FACTORY.set(configuration.buildEntityManagerFactory());
    }

    /**
     *
     */
    @AfterClass
    public static void closeHibernateDerby() {
        ENTITY_MANAGER_FACTORY.get().close();
        try {
            DriverManager.getConnection(JDBC_DERBY_URL + ";shutdown=true");