ShopProductDAO extends BaseIbatisDAO { public Long update(final ShopProduct product) { super.update("SHOP_PRODUCT.update", product); return product.getProductId(); }  @SuppressWarnings("unchecked") List<ShopProduct> query(final Map<String, Object> parameters); Long count(final Map<String, Object> parameters); ShopProduct queryByPk(final Long id); ShopProduct queryDetailByPk(final Long id); Long insert(final ShopProduct product); Long insert(final ShopProductCoupon couponProduct); Long update(final ShopProduct product); Long update(final ShopProductCoupon couponProduct); void reduceStocks(final Map<String, Object> parameters); @SuppressWarnings("unchecked") List<ShopProductCondition> getShopProductConditionByShopProductId(Long productId); ShopProductCondition insertShopProductCondition(ShopProductCondition entity); void deleteShopProductConditionByProductId(Long productId);  }
@Test public void testUpdate() throws SQLException, IllegalAccessException, InvocationTargetException{ ShopProduct product = new ShopProduct(); product.setContent("content"); product.setIsValid("Y"); product.setIsRecommend("Y"); product.setIsHotProduct("Y"); product.setMarketPrice(Long.valueOf(11L)); product.setPointChange(Long.valueOf(12L)); product.setStocks(Long.valueOf(13L)); product.setPictures("pictures"); product.setProductCode("productCode"); product.setProductName("productName"); product.setProductType(Constant.SHOP_PRODUCT_TYPE.COUPON.name()); Long id = shopProductDAO.insert(product); ShopProduct f = shopProductDAO.queryByPk(id); f.setIsHotProduct("N"); f.setPictures("pictures_2"); f.setContent("content_2"); f.setPointChange(Long.valueOf(22L)); shopProductDAO.update(f); String sql = "select * from SHOP_PRODUCT where PRODUCT_ID = " + id; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); rs.next(); Assert.assertEquals("N", rs.getString("IS_HOT_PRODUCT")); Assert.assertEquals("pictures_2", rs.getString("PICTURES")); Assert.assertEquals("content_2", rs.getString("CONTENT")); Assert.assertEquals("22", String.valueOf(rs.getLong("POINT_CHANGE"))); Assert.assertEquals("Y", rs.getString("IS_RECOMMEND")); Assert.assertEquals("11", String.valueOf(rs.getLong("MARKET_PRICE"))); ShopProductCoupon cP_1 = new ShopProductCoupon(); product.setCreateTime(new Date()); product.setModifyTime(new Date()); BeanUtils.copyProperties(cP_1, product); cP_1.setProductId(null); cP_1.setCouponId(Long.valueOf(14L)); Long cpId_1 = shopProductDAO.insert(cP_1); ShopProductCoupon cP_2 = (ShopProductCoupon)shopProductDAO.queryDetailByPk(cpId_1); cP_2.setStocks(Long.valueOf(23L)); cP_2.setCouponId(Long.valueOf(25L)); cP_2.setContent("content_cp"); cP_2.setProductName("productName_cp"); cP_2.setIsHotProduct("N"); shopProductDAO.update(cP_2); String cpSql = "select p.*, cp.* from SHOP_PRODUCT p, SHOP_PRODUCT_COUPON cp where p.PRODUCT_ID = cp.PRODUCT_ID AND p.PRODUCT_ID = " + cpId_1; ResultSet cpRs = stat.executeQuery(cpSql); cpRs.next(); Assert.assertEquals("content_cp", cpRs.getString("CONTENT")); Assert.assertEquals("productName_cp", cpRs.getString("PRODUCT_NAME")); Assert.assertEquals("N", cpRs.getString("IS_HOT_PRODUCT")); Assert.assertEquals("23", String.valueOf(cpRs.getLong("STOCKS"))); Assert.assertEquals("25", String.valueOf(cpRs.getLong("COUPON_ID"))); Assert.assertEquals(Constant.SHOP_PRODUCT_TYPE.COUPON.name(), cpRs.getString("PRODUCT_TYPE")); Assert.assertEquals("Y", cpRs.getString("IS_VALID")); }