public void testDeleteTargetServiceItem() throws DuplicateKeyException {
   assertDatabaseEmpty();
   saveTargetServiceItem(createTarget());
   TargetServiceItem tsi = hibernateTargetServiceItemDao.getAllTargetServiceItems().get(0);
   hibernateTargetServiceItemDao.deleteTargetServiceItem(tsi);
   assertEquals(0, hibernateTargetServiceItemDao.getAllTargetServiceItems().size());
 }
 public void testAddTargetServiceItem() throws DuplicateKeyException {
   assertDatabaseEmpty();
   Target target = createTarget();
   TargetServiceItem tsi = getTargetServiceItem(target);
   hibernateTargetServiceItemDao.saveTargetServiceItem(tsi);
   assertEquals(1, hibernateTargetServiceItemDao.getAllTargetServiceItems().size());
 }
 private void saveTargetServiceItem(Target target) throws DuplicateKeyException {
   TargetServiceItem tsi = new TargetServiceItem();
   ServiceItem si = saveAndGetServiceItem("Solar Panel", "32000", 1);
   tsi.setAmount(si.getAmount());
   tsi.setServiceItem(si);
   tsi.setTarget(target);
   tsi.setServiceItemQty(1);
   hibernateTargetServiceItemDao.saveTargetServiceItem(tsi);
   assertEquals(1, hibernateTargetServiceItemDao.getAllTargetServiceItems().size());
 }
 public void testUpdateTargetServiceItem() throws DuplicateKeyException {
   assertDatabaseEmpty();
   saveTargetServiceItem(createTarget());
   TargetServiceItem tsi = hibernateTargetServiceItemDao.getAllTargetServiceItems().get(0);
   assertEquals(
       1, hibernateTargetServiceItemDao.getAllTargetServiceItems().get(0).getServiceItemQty());
   tsi.setServiceItemQty(13);
   hibernateTargetServiceItemDao.updateTargetServiceItem(tsi);
   assertEquals(
       13, hibernateTargetServiceItemDao.getAllTargetServiceItems().get(0).getServiceItemQty());
 }
 public void testGetTargetServiceItemByTargetId() throws DuplicateKeyException {
   assertDatabaseEmpty();
   saveTargetServiceItem(createTarget());
   TargetServiceItem tsi = hibernateTargetServiceItemDao.getAllTargetServiceItems().get(0);
   Target tgt = tsi.getTarget();
   assertEquals(
       "Solar Panel",
       hibernateTargetServiceItemDao
           .getAllTargetServiceItemByTarget(tgt.getId())
           .get(0)
           .getServiceItem()
           .getTargetName());
 }
 private void assertDatabaseEmpty() {
   assertEquals(0, hibernateTargetDao.getTargetCount());
   assertEquals(0, hibernateAccountDao.getAllAcounts().size());
   assertEquals(0, hibernateServiceItemDao.getAllServiceItems().size());
   assertEquals(0, hibernateTargetServiceItemDao.getAllTargetServiceItems().size());
 }