Esempio n. 1
0
 @Test
 public void test() {
   EntityManagerFactory emf = Persistence.createEntityManagerFactory("FormationJPA");
   assertNotNull(emf);
   EntityManager em = emf.createEntityManager();
   assertNotNull(em);
 }
 @After
 public void tearDown() throws Exception {
   if (em != null) {
     em.close();
   }
   if (emFactory != null) {
     emFactory.close();
   }
   try {
     connection.createStatement().execute("SHUTDOWN");
   } catch (Exception ex) {
   }
 }
 @Before
 public void setUp() throws Exception {
   try {
     Class.forName("org.hsqldb.jdbcDriver");
     connection = DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa", "");
   } catch (Exception ex) {
     ex.printStackTrace();
     fail("Exception during HSQL database startup.");
   }
   try {
     emFactory = Persistence.createEntityManagerFactory("MyPersistence");
     em = emFactory.createEntityManager();
   } catch (Exception ex) {
     ex.printStackTrace();
     fail("Exception during JPA EntityManager instanciation.");
   }
 }