Skip to content

Commit

Permalink
完成Order模块后台测试
Browse files Browse the repository at this point in the history
完成Order模块后台测试
- OrderServiceImpl
  • Loading branch information
wukonggg committed Jul 20, 2015
1 parent 8cd4bb1 commit 7897c8d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION.TXT
Expand Up @@ -28,7 +28,7 @@ mz-g-0.3.2015.07xx
- Goods ok
- SKU ok
- Cart ok
- Order doing | {ok: orderDao, itemDao} {doing: OrderServiceImplTest}
- Order doing | {ok: back} {ready: front}

+ Bug List
- [new]现在数据库里item表cate_code_snapshot怎么都为0?
Expand Down
21 changes: 10 additions & 11 deletions sql/mz-g-deploy.sql
Expand Up @@ -23,11 +23,10 @@ CREATE TABLE IF NOT EXISTS `t_cart` (
`count` int(11) unsigned NOT NULL COMMENT '数量'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='购物车';

-- 正在导出表 mz-g.t_cart 的数据:~2 rows (大约)
-- 正在导出表 mz-g.t_cart 的数据:~3 rows (大约)
DELETE FROM `t_cart`;
/*!40000 ALTER TABLE `t_cart` DISABLE KEYS */;
INSERT INTO `t_cart` (`user_id`, `cust_id`, `sku_more_id`, `count`) VALUES
(1, '2', 93, 1),
(1, '3', 121, 1),
(1, '3', 123, 1);
/*!40000 ALTER TABLE `t_cart` ENABLE KEYS */;
Expand Down Expand Up @@ -86,7 +85,7 @@ DELETE FROM `t_customer`;
/*!40000 ALTER TABLE `t_customer` DISABLE KEYS */;
INSERT INTO `t_customer` (`id`, `cid`, `name`, `birth`, `msisdn`, `address`, `remark`, `payment_clothing`, `state`) VALUES
(1, '00000004', '非会员顾客', '2014-11-16', '0', '0', NULL, 0, '1'),
(2, '99999999999', 'Abel', '2015-04-10', '18181798763', 'sdf', '11', 2900, '1'),
(2, '99999999999', 'Abel', '2015-04-10', '18181798763', 'sdf', '11', 2908, '1'),
(3, '99999999998', 'Black', '2015-04-10', '18982746372', NULL, NULL, 1000, '1'),
(4, '99999999997', 'Candy', '2015-04-10', '18238374659', NULL, NULL, 5000, '1'),
(5, '99999999996', 'Daniel', '2015-04-10', '18928374678', NULL, NULL, 0, '1'),
Expand Down Expand Up @@ -153,9 +152,9 @@ INSERT INTO `t_item` (`id`, `sku_id`, `sku_more_id`, `cate_code_snapshot`, `spri
(6, 13, 92, '0', 120, 106, 1, 105, NULL, 0, NULL, '0', '1', 4),
(7, 12, 113, '0', 100, 88, 1, 88, NULL, 0, NULL, '0', '1', 4),
(8, 13, 92, '0', 120, 120, 1, 120, NULL, 0, NULL, '0', '1', 5),
(9, 12, 113, '0', 100, 100, 2, 200, NULL, 0, NULL, '0', '1', 6),
(9, 12, 113, '0', 100, 100, 5, 500, NULL, 0, NULL, '0', '1', 6),
(10, 12, 113, '0', 100, 100, -1, -100, '2015-07-06 00:13:35', 1, '1', 'akakakk', '2', 6),
(11, 12, 113, 'junit_update', 100, 100, 1, 100, NULL, 0, NULL, NULL, '1', 0);
(15, 12, 113, '0', 100, 100, -1, -100, '2015-07-20 10:43:36', 1, '2', '就不告诉你。。。', '2', 6);
/*!40000 ALTER TABLE `t_item` ENABLE KEYS */;


Expand Down Expand Up @@ -196,9 +195,9 @@ CREATE TABLE IF NOT EXISTS `t_sku` (
`state` char(2) NOT NULL COMMENT '0:已删除;1:上架;2:下架',
`goods_id` int(11) NOT NULL COMMENT '商品id',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COMMENT='商品SKU主表';
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='商品SKU主表';

-- 正在导出表 mz-g.t_sku 的数据:~6 rows (大约)
-- 正在导出表 mz-g.t_sku 的数据:~8 rows (大约)
DELETE FROM `t_sku`;
/*!40000 ALTER TABLE `t_sku` DISABLE KEYS */;
INSERT INTO `t_sku` (`id`, `sid`, `model`, `type`, `ptime`, `pprice`, `sprice`, `img`, `ctime`, `utime`, `state`, `goods_id`) VALUES
Expand All @@ -221,20 +220,20 @@ CREATE TABLE IF NOT EXISTS `t_sku_more` (
`count` int(11) unsigned NOT NULL COMMENT '数量',
`remark` varchar(50) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=163 DEFAULT CHARSET=utf8 COMMENT='商品SKU更多表';
) ENGINE=InnoDB AUTO_INCREMENT=189 DEFAULT CHARSET=utf8 COMMENT='商品SKU更多表';

-- 正在导出表 mz-g.t_sku_more 的数据:~28 rows (大约)
-- 正在导出表 mz-g.t_sku_more 的数据:~38 rows (大约)
DELETE FROM `t_sku_more`;
/*!40000 ALTER TABLE `t_sku_more` DISABLE KEYS */;
INSERT INTO `t_sku_more` (`id`, `sku_id`, `size`, `count`, `remark`) VALUES
(92, 13, '100', 10, '备注备注备注'),
(93, 13, '110', 9, '备注备注备注'),
(93, 13, '110', 7, '备注备注备注'),
(94, 13, '120', 10, '备注备注备注'),
(95, 13, '130', 10, '备注备注备注'),
(96, 13, '140', 10, '备注备注备注'),
(97, 13, '150', 10, '备注备注备注'),
(98, 13, '160', 7, '备注备注备注'),
(113, 12, '100', 30, ''),
(113, 12, '100', 31, ''),
(114, 12, '110', 9, '备注备注备注'),
(115, 12, '120', 10, '备注备注备注'),
(116, 12, '130', 10, '备注'),
Expand Down
@@ -1,22 +1,29 @@
package band.wukong.mz.g.sale.servcie.impl;

import band.wukong.mz.base.bean.Period;
import band.wukong.mz.g.AppConst;
import band.wukong.mz.g.category.SimpleCateConst;
import band.wukong.mz.g.customer.service.CustomerService;
import band.wukong.mz.g.privilege.bean.User;
import band.wukong.mz.g.sale.bean.Cart;
import band.wukong.mz.g.sale.bean.Item;
import band.wukong.mz.g.sale.service.impl.OrderServiceImpl;
import band.wukong.mz.g.sale.bean.Order;
import band.wukong.mz.g.sale.service.CartService;
import band.wukong.mz.g.sale.service.DiscountRule;
import band.wukong.mz.g.sale.service.OrderService;
import band.wukong.mz.g.sku.dao.SkuMoreDao;
import band.wukong.mz.g.sku.dao.impl.SkuMoreDaoImpl;
import band.wukong.mz.nutz.NutzTestHelper;
import band.wukong.mz.util.DateUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.nutz.dao.QueryResult;
import org.nutz.ioc.Ioc;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* As you see...
Expand All @@ -26,16 +33,18 @@
public class OrderServiceImplTest {

private Ioc ioc;
private OrderServiceImpl orderService;
private OrderService orderService;
private SkuMoreDao skuMoreDao;
private CustomerService custService;
private CartService cartService;

@Before
public void setUp() throws ClassNotFoundException {
ioc = NutzTestHelper.createIoc();
orderService = ioc.get(OrderServiceImpl.class);
skuMoreDao = ioc.get(SkuMoreDaoImpl.class);
orderService = ioc.get(OrderService.class);
skuMoreDao = ioc.get(SkuMoreDao.class);
custService = ioc.get(CustomerService.class);
cartService = ioc.get(CartService.class);
}

@After
Expand All @@ -54,9 +63,82 @@ public void listDetail() {
String qcond = "99999999998"; //cid
Period period = new Period(DateUtils.convert2date("2015-01-01"), DateUtils.convert2date("2015-07-20"));
User user = new User();
// user.setId();
// orderService.listDetail(qcond, period, );
user.setId(1L);
QueryResult qr = orderService.listDetail(qcond, period, user, 0, AppConst.PAGE_NUM_DFT);
Assert.assertNotNull(qr.getPager().getRecordCount());
Assert.assertTrue(qr.getList(Order.class).size() > 0);
}

@Test
public void pay() {
// 1、pay方法是否返回了新生成的order
// 2、库存数量变化
// 3、购物车变化
// 4、paymentClothing变化


final Long CUST_ID = 2L;
final Long CUST_CID = 99999999999L;
final Long USER_ID = 1L;
final Long SKU_MORE_ID = 93L;
final String CATE_CODE = SimpleCateConst.CATE_CODE_A_SYTZ;
final int SPRICE = 120;
final int DCOUNT = 1;
final double PAYMENT = 108;


int pre_skuMore_count = skuMoreDao.find(SKU_MORE_ID).getCount();
long pre_paymentClothing = custService.find(CUST_ID).getPaymentClothing();


Cart[] carts = new Cart[1];
Cart cart = new Cart();
cart.setCustId(CUST_ID);
cart.setSkuMoreId(SKU_MORE_ID);
cart.setCount(DCOUNT);
cart.setSprice(SPRICE);
cart.setCount(DCOUNT);
cart.setPayment(PAYMENT);
carts[0] = cart;
Order order = orderService.pay(carts, USER_ID);

// 1、pay方法是否返回了新生成的order
Assert.assertNotNull(order);
Assert.assertTrue(order.getItems().size() == 1);

// 2、库存数量变化
int curr_skuMore_count = skuMoreDao.find(SKU_MORE_ID).getCount();
Assert.assertTrue(pre_skuMore_count == curr_skuMore_count + DCOUNT);

// 3、购物车变化
Map<String, List<Cart>> userCartsMap= cartService.listGroupByCust(USER_ID);
Assert.assertTrue(null != userCartsMap);
List<Cart> cartsOfCust = userCartsMap.get(CUST_CID);
if (null != cartsOfCust) {
for (Cart c : cartsOfCust) {
// 如果找到了key为cid的CartList中有skuMoreId,说明没有删掉
Assert.assertTrue(SKU_MORE_ID != c.getSkuMoreId());
}
} // 如果carsOfCust为null,则说明ok。所以就不用else了。

// 4、paymentClothing变化
if(DiscountRule.hasClothingDiscount(CATE_CODE)) {
long payment = order.getItems().get(0).getPayment();
long curr_paymentClothing = custService.find(CUST_ID).getPaymentClothing();
Assert.assertTrue(payment + pre_paymentClothing == curr_paymentClothing);
}

// FIXME 补充失败情况的单元测试用例
// 1、用户是否存在
// 2、顾客是否存在
// 3、购买数量大于
}

@Test
public void findItemWithOrder() {
Item item = orderService.findItemWithOrder(9);
Assert.assertNotNull(item);
Assert.assertNotNull(item.getOrder());
}

@Test
Expand Down

0 comments on commit 7897c8d

Please sign in to comment.