@Before public void init() { notaBDAO = new NotaBDAO(); try { db = new DBAccess(); conn = db.getConnection(); notaB1 = new NotaB(); notaB1.setIdNotaB(1); notaB1.setDescrizione("asd"); notaB1.setData(cd.getTime()); notaB1.setIdStrumento(2); notaB1.setIdUtente(1); notaB2 = new NotaB(); // notaB2.setIdNotaB(2); notaB2.setDescrizione("asd"); // notaB2.setData(cd.getTime()); notaB2.setIdStrumento(2); notaB2.setIdUtente(1); } catch (DBAccessException e) { fail(e.getMessage()); } }
@Test public void testUpdate() { try { NotaB notaBU = new NotaB(); notaBU.setDescrizione("asd2"); boolean test = notaBDAO.update(conn, notaBU, notaB1); db.rollbackConnection(conn); assertTrue(test); } catch (DAOException e) { fail(e.getMessage()); } catch (DBAccessException e) { fail(e.getMessage()); } finally { try { db.closeConnection(conn); } catch (DBAccessException e) { e.printStackTrace(); } } // TEST 2 try { notaBDAO.update(conn, new Allegato(), notaB1); fail(); } catch (DAOException e) { assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B)); } finally { try { db.closeConnection(conn); } catch (DBAccessException e) { e.printStackTrace(); } } // TEST 3 try { notaBDAO.update(conn, null, notaB1); fail(); } catch (DAOException e) { // return; assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B)); } finally { try { db.closeConnection(conn); } catch (DBAccessException e) { e.printStackTrace(); } } }