ShopProductDAO extends BaseIbatisDAO { public ShopProduct queryDetailByPk(final Long id) { ShopProduct p = (ShopProduct) super.queryForObject("SHOP_PRODUCT.queryByPk", id); if (null != p && Constant.SHOP_PRODUCT_TYPE.COUPON.name().equals(p.getProductType())) { return (ShopProductCoupon) super.queryForObject("SHOP_PRODUCT.queryCouponByPk", id); } return p; }  @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 testQueryDetailByPk(){ ShopProduct product = new ShopProduct(); product.setProductName("productName"); product.setProductType(Constant.SHOP_PRODUCT_TYPE.PRODUCT.name()); Long pId = shopProductDAO.insert(product); ShopProduct p = shopProductDAO.queryDetailByPk(pId); Assert.assertEquals("productName", p.getProductName()); Assert.assertEquals(Constant.SHOP_PRODUCT_TYPE.PRODUCT.name(),p.getProductType()); ShopProductCoupon c = new ShopProductCoupon(); c.setProductName("couponProduct"); c.setProductType(Constant.SHOP_PRODUCT_TYPE.COUPON.name()); Long cId = shopProductDAO.insert(c); ShopProduct cP = shopProductDAO.queryDetailByPk(cId); Assert.assertEquals("couponProduct", cP.getProductName()); Assert.assertEquals(Constant.SHOP_PRODUCT_TYPE.COUPON.name(), cP.getProductType()); }