package br.com.delogic.asd.config;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import br.com.delogic.asd.entities.Person;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class SpringTestBase extends Assert {

    @Configuration
    @Import(SpringTestConfig.class)
    static class SpringConfigInit {

    }

    @Inject
    private JpaTransactionManager transactionManager;

    private TransactionStatus transactionStatus;

    @PersistenceContext
    protected EntityManager entityManager;

    protected void beginTransaction() {
        transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
    }

    protected void commitTransaction() {
        if (transactionManager == null || transactionStatus == null) throw new IllegalStateException(
            "A transação não foi aberta e provavelmente o begin() não foi chamado");

        transactionManager.commit(transactionStatus);
    }

    // private final org.slf4j.Logger logger =
    // LoggerFactory.getLogger(EntityRepositoryTest.class);

    static {
        /* desligar o log para melhorar performance */
        // Log4jManager.setLevel(Level.INFO);
    }

    @Test
    public void teste() {
        Person p = new Person();
        p.setName("Célio Silva");

        beginTransaction();
        entityManager.persist(p);
        entityManager.flush();
        commitTransaction();

        assertEquals("Célio Silva", entityManager.find(Person.class, 1).getName());

    }

}

@@ -172,31 +172,8 @@
 rt;%0A
-import org.junit.Test;%0A
 impo
@@ -727,52 +727,8 @@
 n;%0A%0A
-import br.com.delogic.asd.entities.Person;%0A%0A
 @Run
@@ -1830,325 +1830,6 @@
  %7D%0A%0A
-    @Test%0A    public void teste() %7B%0A        Person p = new Person();%0A        p.setName(%22C%C3%A9lio Silva%22);%0A%0A        beginTransaction();%0A        entityManager.persist(p);%0A        entityManager.flush();%0A        commitTransaction();%0A%0A        assertEquals(%22C%C3%A9lio Silva%22, entityManager.find(Person.class, 1).getName());%0A%0A    %7D%0A%0A
 %7D%0A

Fix test base