Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. package br.ufal.ic.academico;
  2.  
  3. import br.ufal.ic.academico.db.Database;
  4. import br.ufal.ic.academico.model.*;
  5. import io.dropwizard.testing.junit5.DAOTestExtension;
  6. import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
  7. import lombok.SneakyThrows;
  8. import java.lang.*;
  9.  
  10. import static org.junit.jupiter.api.Assertions.*;
  11.  
  12. import org.hibernate.SessionFactory;
  13. import org.junit.jupiter.api.BeforeEach;
  14. import org.junit.jupiter.api.Test;
  15. import org.junit.jupiter.api.extension.ExtendWith;
  16. import io.dropwizard.hibernate.HibernateBundle;
  17.  
  18. /**
  19. *
  20. * @author Arthur
  21. */
  22.  
  23. @ExtendWith(DropwizardExtensionsSupport.class)
  24. public class DBTest {
  25.  
  26. public DAOTestExtension dbTesting = DAOTestExtension.newBuilder()
  27. .addEntityClass(Course.class)
  28. .addEntityClass(Department.class)
  29. .addEntityClass(Drca.class)
  30. .addEntityClass(Offer.class)
  31. .addEntityClass(Secretariat.class)
  32. .addEntityClass(Student.class)
  33. .addEntityClass(Subject.class)
  34. .addEntityClass(Teacher.class).build();
  35.  
  36. private Database dao;
  37.  
  38. @BeforeEach
  39. @SneakyThrows
  40. public void setUp() {
  41. System.out.println("setUp");
  42. dao = new Database(dbTesting.getSessionFactory());
  43. }
  44.  
  45. @Test
  46. public void testStudentCreate(){
  47. Student c1 = new Student("c1", "00000");
  48. Student saved = (Student)dao.persist(Student.class, new Student("c1", "0000"));
  49.  
  50. assertAll(() -> assertNotNull(saved),
  51. () -> assertNotNull(saved.getId()),
  52. () -> assertEquals(c1.getName(), saved.getName()),
  53. () -> assertNull(dbTesting.inTransaction(() -> dao.persist(null))));
  54. }
  55.  
  56. @Test
  57. public void testStudentRead(){
  58. Student c1 = new Student("c1", "00000");
  59. Student c2 = new Student("c2", "11111");
  60. Student c3 = new Student("c1", "00000");
  61. //
  62. // dbTesting.inTransaction(() -> dao.persist(c1));
  63. // dbTesting.inTransaction(() -> dao.persist(c3));
  64. //
  65. // assertAll(() -> assertEquals(c1, dbTesting.inTransaction(() -> dao.get(Student.class, c1.getId()))),
  66. // () -> assertNull(dbTesting.inTransaction(() -> dao.get(Student.class, c2))),
  67. // () -> assertNotEquals(c1, dbTesting.inTransaction(() -> dao.get(Student.class, c3.getId()))));
  68. }
  69.  
  70. @Test
  71. public void testStudentUpdate(){
  72.  
  73. }
  74.  
  75. @Test
  76. public void testStudentDelete(){
  77. Student c1 = new Student("c1", "00000");
  78. dbTesting.inTransaction(() -> dao.persist(Student.class, c1));
  79. dbTesting.inTransaction(() -> dao.delete(Student.class, c1.getId()));
  80.  
  81. assertNull(dbTesting.inTransaction(() -> dao.get(Student.class, c1.getId())));
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement