Advertisement
mc_zefirka

JDBCTests

Apr 18th, 2021
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1. package jdbc;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.assertNotEquals;
  5. import static org.junit.Assert.assertNotNull;
  6. import static org.junit.Assert.assertNull;
  7. import static org.junit.Assert.assertTrue;
  8.  
  9. import org.junit.Ignore;
  10. import org.junit.Test;
  11.  
  12. import com.itstep.mvn.app.jdbc.dao.EmployeeDAO;
  13. import com.itstep.mvn.app.jdbc.dao.EmployeeDAOImpl;
  14. import com.itstep.mvn.app.jdbc.dao.OfficeDAO;
  15. import com.itstep.mvn.app.jdbc.dao.OfficeDAOImpl;
  16. import com.itstep.mvn.app.jdbc.dao.ProductsDAOImpl;
  17. import com.itstep.mvn.app.jdbc.dao.ProductsDao;
  18. import com.itstep.mvn.app.jdbc.dao.UniverDao;
  19. import com.itstep.mvn.app.jdbc.dao.UniverDaoImpl;
  20. import com.itstep.mvn.app.model.jdbc.Employee;
  21. import com.itstep.mvn.app.model.jdbc.Office;
  22. import com.itstep.mvn.app.model.jdbc.Product;
  23. import com.itstep.mvn.app.model.jdbc.Univer;
  24.  
  25. public class JDBCTests {
  26.     @Test
  27.     @Ignore
  28.     public void t1() {
  29.         UniverDao dao = new UniverDaoImpl();
  30.         assertNull(dao.getUniverById(-2));
  31.         Univer u = dao.getUniverById(2);
  32.         assertNotNull(u);
  33.         System.out.println(u);
  34.     }
  35.    
  36.    
  37.     @Test
  38.     @Ignore
  39.     public void t2() {
  40.         UniverDao dao = new UniverDaoImpl();
  41.         Univer u = new Univer();
  42.         u.setName("BGU");
  43.         u.setLocation("Minsk");
  44.         u.setRate(5);
  45.    
  46. //      assertTrue
  47.     }
  48.    
  49.     @Test
  50.     @Ignore
  51.     public void t3() {
  52.         UniverDao dao = new UniverDaoImpl();
  53.        
  54.         assertTrue(dao.removeUniverById(3));
  55.        
  56.     }
  57.    
  58.     @Test
  59.     @Ignore
  60.     public void t44() {
  61.        
  62.         ProductsDao prDao = new ProductsDAOImpl();
  63.        
  64. //      System.out.println(prDao.getProduct("S10_1678"));
  65.        
  66.         Product product = new Product();
  67.         product.setBuyPrice(60);
  68.        
  69.         assertTrue(prDao.addProduct(product));
  70.        
  71.     }
  72.    
  73.     @Test
  74.     @Ignore
  75.     public void t4() {
  76.         EmployeeDAO dao = new EmployeeDAOImpl();
  77.         Employee empl = dao.getEmployee(1056);
  78.         System.out.println(empl);
  79.         assertNotNull(empl.getReportsTo());
  80.        
  81.     }
  82.    
  83.     @Test
  84.     @Ignore
  85.     public void t5() {
  86.         EmployeeDAO dao = new EmployeeDAOImpl();
  87.         Employee empl = dao.getEmployee(1088);
  88.         System.out.println(empl);
  89.         assertNotNull(empl.getReportsTo());
  90.     }
  91.    
  92.     @Test
  93.     @Ignore
  94.     public void t6() {
  95.         OfficeDAO dao = new OfficeDAOImpl();
  96.         Office office = dao.getOffice("7");
  97.         System.out.println(office);
  98.         assertNotNull(office);
  99.         //assertNotNull(office.getEmployees());
  100.         //assertTrue(office.getEmployees().size() > 0);
  101.     }
  102.    
  103.     @Test
  104.     public void officeTest() {
  105.        
  106.         Office o = new Office("10", "Minsk", "+375333142890", "K. Marksa 32", "", "MINSK", "BRL", "220052", "EMEA");
  107.         OfficeDAO dao = new OfficeDAOImpl();
  108.         assertTrue(dao.createOffice(o));
  109.         Office dbOffice = dao.getOffice("10");
  110.         assertEquals(o, dbOffice);
  111.        
  112.         Office officeToUpdate = new Office("10", "Minsk", "+375777777777", "K. Marksa 32", "", "MINSK", "BRL", "220052", "NA");
  113.         assertTrue(dao.updateOffice(officeToUpdate));
  114.         assertNotEquals(o, dao.getOffice("10"));
  115.         assertTrue(dao.removeOffice("10"));
  116.         assertNull(dao.getOffice("10"));
  117.        
  118.     }
  119.    
  120.     @Test
  121.     public void emplTest() {
  122.        
  123.         EmployeeDAO edao = new EmployeeDAOImpl();
  124.         OfficeDAO odao = new OfficeDAOImpl();
  125.         Employee eRep = edao.getEmployee(1056); //  Patterson Mary
  126.         Office office = odao.getOffice("5");
  127.        
  128.         Employee e = new Employee(2000, "Ivanov", "Ivan", "X", "gmail", office, eRep, "TESTER");
  129.        
  130.         assertTrue(edao.createEmployee(e));
  131.        
  132.         Employee dbEmpl = edao.getEmployee(2000);
  133.         assertEquals(e, dbEmpl);
  134.        
  135.         Employee emplToUpdate = new Employee(2000, "NeIvanov", "NeIvan", "X", "gmail", office, eRep, "TESTER");
  136.         assertTrue(edao.updateEmployee(emplToUpdate));
  137.        
  138.         assertNotEquals(e, edao.getEmployee(2000));
  139.         assertTrue(edao.removeEmployee(2000));
  140.         assertNull(edao.getEmployee(2000));
  141.        
  142.     }
  143.    
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement