<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.denevell.tomcat.entities.write.AnotherThing</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:/home/YOURUSERNAME/test.db" />
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
</persistence>
public class JPAStarterTest {
@Test
public void addAnotherThing() {
// Arrange
AnotherThing at = new AnotherThing();
at.setText("hii");
// Act
tx.begin();
em.persist(at);
tx.commit();
// Assert
assertNotNull("Id should not be null", at.getId());
List<AnotherThing> list = em.createNamedQuery("listAll", AnotherThing.class).getResultList();
assertEquals("Table has one entity", 1, list.size());
assertEquals("Table has correcttext", "hii", list.get(0).getText());
}
@BeforeClass
public static void beforeClass() {
emf = Persistence.createEntityManagerFactory("exampletest");
em = emf.createEntityManager();
}
@AfterClass
public static void afterClass() {
em.close();
emf.close();
}
@Before
public void before() {
tx = em.getTransaction();
}
private static EntityManagerFactory emf;
private static EntityManager em;
private EntityTransaction tx;
}
jpa java-testing jpa-testing junit
Page 1 of 1