* Test of update method, of class OrderDAO.
*/
@Test
public void testUpdate() {
Long oId;
Order o = newOrder(customer, null, null, null, extraServices, tyres, BigDecimal.valueOf(2690.9));
dao.create(o);
oId = o.getId();
o.setId(null);
//
try {
dao.update(null);
fail("Order null and didn't throw exception");
} catch (DataAccessException ex) {
//ok
} catch (Exception ex) {
fail("Order null and didn't throw appropriate exception");
}
try {
dao.update(o);
fail("Order ID null and didn't throw exception");
} catch (DataAccessException ex) {
//ok
} catch (Exception ex) {
fail("Order ID null and didn't throw appropriate exception");
}
//
o.setId(oId);
Date d = newDate("22.1.2010 22:15:00");
o.setOrderNewDate(d);
dao.update(o);
//
Order o2 = dao.get(o.getId());
assertEquals("Orders are not the same", o2, o);
assertDeepEquals(o2, o);
//
// test tyre remove and add
o.getTyres().remove(TyrePosition.FRONT_LEFT);
Tyre t = newTyre(12D, "AJ22", "BRPL", "Matador", BigDecimal.valueOf(77.7));
tyreDAO.create(t);
o.getTyres().put(TyrePosition.REAR_RIGHT, t);
dao.update(o);
//
Order o3 = dao.get(o.getId());
assertEquals("Orders are not the same", o3, o);
assertDeepEquals(o3, o);
//
// test extra services remove and add
o.getExtraServices().remove(o.getExtraServices().iterator().next());
ExtraService es = newExtraService("Baking pastery", "You wouldn't drive hungry!", BigDecimal.ZERO);
extraServiceDAO.create(es);
o.getExtraServices().add(es);
dao.update(o);
//
Order o4 = dao.get(o.getId());
assertEquals("Orders are not the same", o4, o);
assertDeepEquals(o4, o);
}