/
SimpleTest.java
44 lines (38 loc) · 1.06 KB
/
SimpleTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.datanucleus.test;
import org.junit.*;
import javax.persistence.*;
import static org.junit.Assert.*;
import mydomain.model.*;
import org.datanucleus.util.NucleusLogger;
public class SimpleTest
{
@Test
public void testSimple()
{
NucleusLogger.GENERAL.info(">> test START");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyTest");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try
{
tx.begin();
// [INSERT code here to persist object required for testing]
tx.commit();
}
catch (Throwable thr)
{
NucleusLogger.GENERAL.error(">> Exception thrown persisting data", thr);
fail("Failed to persist data : " + thr.getMessage());
}
finally
{
if (tx.isActive())
{
tx.rollback();
}
em.close();
}
emf.close();
NucleusLogger.GENERAL.info(">> test END");
}
}