ShopProductDAO extends BaseIbatisDAO { public Long insert(final ShopProduct product) { super.insert("SHOP_PRODUCT.insert", 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 testInsert() 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); String sql = "select * from SHOP_PRODUCT where PRODUCT_ID = " + id; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); rs.next(); Assert.assertEquals("productCode", rs.getString("PRODUCT_CODE")); Assert.assertEquals("productName", rs.getString("PRODUCT_NAME")); Assert.assertEquals(Constant.SHOP_PRODUCT_TYPE.COUPON.name(), rs.getString("PRODUCT_TYPE")); Assert.assertEquals("Y", rs.getString("IS_VALID")); Assert.assertEquals("Y", rs.getString("IS_HOT_PRODUCT")); Assert.assertEquals("Y", rs.getString("IS_RECOMMEND")); Assert.assertEquals("pictures", rs.getString("PICTURES")); Assert.assertEquals("content", rs.getString("CONTENT")); Assert.assertEquals("11", String.valueOf(rs.getLong("MARKET_PRICE"))); Assert.assertEquals("12", String.valueOf(rs.getLong("POINT_CHANGE"))); Assert.assertEquals("13", String.valueOf(rs.getLong("STOCKS"))); ShopProductCoupon couponProduct = new ShopProductCoupon(); product.setCreateTime(new Date()); product.setModifyTime(new Date()); BeanUtils.copyProperties(couponProduct, product); couponProduct.setProductId(null); couponProduct.setCouponId(Long.valueOf(14L)); Long cpId = shopProductDAO.insert(couponProduct); String cpSql = "select p.PRODUCT_NAME PRODUCT_NAME, p.PRODUCT_TYPE PRODUCT_TYPE, cp.COUPON_ID COUPON_ID from SHOP_PRODUCT p, SHOP_PRODUCT_COUPON cp where p.PRODUCT_ID = cp.PRODUCT_ID AND p.PRODUCT_ID = " + cpId; ResultSet cpRs = stat.executeQuery(cpSql); cpRs.next(); Assert.assertEquals("productName", cpRs.getString("PRODUCT_NAME")); Assert.assertEquals("14", String.valueOf(cpRs.getLong("COUPON_ID"))); Assert.assertEquals(Constant.SHOP_PRODUCT_TYPE.COUPON.name(), cpRs.getString("PRODUCT_TYPE")); }