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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package com.icl.m3.relationTest;
import static org.junit.Assert.*;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.icl.m3.model.Author;
public class Jl2tho {
private static EntityManager em;
private static EntityManagerFactory emf;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
emf = Persistence.createEntityManagerFactory("sample");
em = emf.createEntityManager();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
em.close();
emf.close();
}
@Test
public void authorTest() {
EntityTransaction tx = em.getTransaction();
tx.begin();
Author author = new Author();
author.setFirstName("DEDE");
author.setLastName("MEME");
em.persist(author);
int idAuthor = author.getId();
assertNotNull("Id not null", idAuthor);
Author monAutheurRetrouve = em.find(Author.class, idAuthor);
assertNotNull("Author from database", monAutheurRetrouve);
assertEquals("getFirstName", "DEDE",
monAutheurRetrouve.getFirstName());
assertEquals("getLastName", "MEME", monAutheurRetrouve.getLastName());
assertNull("BirthDate Null", monAutheurRetrouve.getBirthDate());
tx.commit();
}
} |
Partager