int nrPrezenteTest = 20;
int idObiectTest = 5;
final int n = 3;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Student studentTest = new Student();
studentTest.setIdGrupa(1);
studentTest.setAnStudiu(anStudiuTest);
studentTest.setEmail(emailTest);
studentTest.setNrMatricol(numarMatricolTest);
studentTest.setNume(numeTest);
studentTest.setPrenume(prenumeTest);
em.persist(studentTest);
for (int i = 0; i < n; i++) {
Catalog catalogTest = new Catalog();
catalogTest.setIdStudent(studentTest.getIdStudent());
catalogTest.setDataNotei(new Date());
catalogTest.setIdObiect(idObiectTest + i);
catalogTest.setNota(notaTest);
catalogTest.setNrPrezente(nrPrezenteTest);
studentTest.getCatalog().add(catalogTest);
}
em.persist(studentTest);
em.getTransaction().commit();
em.getTransaction().begin();
Student st = new Student();
st = em.find(Student.class, studentTest.getIdStudent());
Query q = em.createQuery("select ct from Catalog ct ");
List<Catalog> ct = new ArrayList<Catalog>();
ct = (List<Catalog>) q.getResultList();
assertEquals(ct.size(), 3);
assertTrue(ct.equals(st.getCatalog()));
em.getTransaction().commit();
em.close();
}