/**
* Copyright 2014 Comcast Cable Communications Management, LLC
*
* This file is part of CATS.
*
* CATS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CATS 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CATS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.comcast.cats.keymanager.entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
/**
* This class forms the basis for testing any of the models. It creates an
* EntityManager, begins a transaction, creates fake data, executes the tests,
* and then rolls back the transaction so that the DB doesn't get messed up.
*/
@org.junit.Ignore
public abstract class AbstractJPABaseClass {
/**
* The EntityManager that should be used for the model tests.
*/
protected EntityManager eMgr;
/**
* The EntityManagerFactor that creates the EntityManager used.
*/
private EntityManagerFactory emf;
/**
* Before the class is initialized, setup Log4J.
*/
@BeforeClass
public static void setupLogging() {
org.apache.log4j.BasicConfigurator.configure();
}
/**
* DBUnit will populate fake data prior to execution.
*
* @throws java.lang.Exception
* put here to avoid handling the error conditions, just let the
* test fail
*/
@Before
public void setUp() throws Exception {
emf = Persistence.createEntityManagerFactory("key-manager-pu");
eMgr = emf.createEntityManager();
final EntityTransaction xact = eMgr.getTransaction();
xact.begin();
}
/**
* Since DBUnit will be clearing the Database before each test commit to the
* database to ensure this works as expected.
*/
@After
public void tearDown() {
final EntityTransaction xact = eMgr.getTransaction();
xact.commit();
eMgr.close();
emf.close();
}
}