Package org.bigk.invoices.test

Source Code of org.bigk.invoices.test.SpringJPATests

package org.bigk.invoices.test;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.bigk.invoices.model.Purchaser;
import org.junit.After;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

import com.fixy.Fixy;
import com.fixy.JPAFixy;


@TestExecutionListeners(TransactionalTestExecutionListener.class)
@Transactional
public abstract class SpringJPATests
    extends AbstractJUnit4SpringContextTests {

  @PersistenceContext
  protected EntityManager em;

  protected Map<Class<? extends Purchaser>, List<Long>> fixtureEntityIds;
 
  @After
  public void flushSession() {
    em.flush();
  }
 
  protected void loadFixture(String filename) {
    Fixy fixy = JPAFixy.create(em);
    fixy.load(convertRelativePathToAbsolute(filename));
    flushAndClearEM();
  }
 
  private String convertRelativePathToAbsolute(String filename) {
    if (filename.startsWith("/")) {
      return filename;
    } else {
      return "/" + getClass().getPackage().getName().replace('.', File.separatorChar) + File.separator + filename;
    }
  }
 
  protected void flushAndClearEM() {
    em.flush();
    em.clear();
  }
}
TOP

Related Classes of org.bigk.invoices.test.SpringJPATests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.