@Test public void testCreate() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByIdCommodity(commodityView.getIdCommodity()); commodityView.setId(c.get(0).getId()); assertEquals(c.get(0), commodityView); }
@Test public void testDelete() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByIdCommodity(commodity.getId()); for (CommodityView test : c) commodityViewDAO.delete(test.getId()); assertThat( "Expected empty List ", commodityViewDAO.getByIdCommodity(commodity.getId()).isEmpty(), is(true)); }
@Test public void testGetByImageType() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByImageType(ImageType.bmp); commodityView.setId(c.get(0).getId()); assertEquals(c.get(0), commodityView); }
private void fillDbTables() throws Exception { for (Category cat : categories) categoryDAO.create(cat); for (Producer p : producers) producerDAO.create(p); Long idProducer = producerDAO.getByName("Apple").getId(); Long idCategory = categoryDAO.getByName("Tablet").getId(); commodity.setIdProducer(idProducer); commodity.setIdCategory(idCategory); commodityDAO.create(commodity); commodity = commodityDAO.getByName("Ipad4"); commodityView.setIdCommodity(commodity.getId()); }
@Test public void testUpdate() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByIdCommodity(commodity.getId()); CommodityView view = c.get(0); long id = view.getId(); long idCommodity = view.getIdCommodity(); someCommodityView = new CommodityView(); someCommodityView.setId(id); someCommodityView.setIdCommodity(idCommodity); someCommodityView.setCommodityPhoto(view.getCommodityPhoto()); someCommodityView.setCommodityPhotoType(ImageType.png); someCommodityView.setGalleryPhoto(true); commodityViewDAO.update(someCommodityView); CommodityView test = commodityViewDAO.getById(id); assertEquals(someCommodityView, test); }