use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncParamInvalid.
/**
* #1
* 模拟参数问题
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncParamInvalid() throws Exception {
Object[][] test = new Object[][] { // 依次对应必填参数 渠道类型 订单标题 订单金额 订单流水号 收款码
new Object[] { null, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_APP, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "试一个很长的title--参数公共返回参数取值及含义参见支付公共返回参数部分", null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", -1, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", 3, null, null }, new Object[] { BCReqParams.BCChannelTypes.WX_SCAN, "正常title", 3, "123", null }, new Object[] { BCReqParams.BCChannelTypes.WX_SCAN, "正常title", 3, "123456789ABCDE", null } };
for (Object[] objects : test) {
final CountDownLatch localLatch = new CountDownLatch(1);
pay.reqOfflinePayAsync((BCReqParams.BCChannelTypes) objects[0], (String) objects[1], (Integer) objects[2], (String) objects[3], null, (String) objects[4], "terminalid", null, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_FAIL, payResult.getResult());
Assert.assertEquals((Integer) BCPayResult.APP_INTERNAL_PARAMS_ERR_CODE, payResult.getErrCode());
Assert.assertEquals(BCPayResult.FAIL_INVALID_PARAMS, payResult.getErrMsg());
// System.out.println(payResult.getDetailInfo());
localLatch.countDown();
}
});
localLatch.await(2000, TimeUnit.MILLISECONDS);
}
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncSucc.
/**
* #3
* 正常response为200的情况
* @throws Exception
*/
@Test
public void testQueryBillsAsyncSucc() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
// please note this content is fake, there should be more content for bills, here just keep one record for the limit of space
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"bills\":[{\"spay_result\":false,\"create_time\":1447658025661,\"total_fee\":1,\"channel\":\"UN\",\"trade_no\":\"\",\"bill_no\":\"bc1447657931\",\"optional\":\"{\\\"test\\\":\\\"willreturn\\\"}\",\"revert_result\":false,\"title\":\"你的订单标题\",\"sub_channel\":\"UN_WEB\",\"refund_result\":false}]}";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
query.queryBillsAsync(BCReqParams.BCChannelTypes.ALL, null, null, null, 2, 10, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryBillsResult);
BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
Assert.assertEquals((Integer) 0, billsResult.getResultCode());
// 最多可以获取到limit条数据
Assert.assertTrue(billsResult.getCount() == billsResult.getBills().size());
BCBillOrder billOrder = billsResult.getBills().get(0);
Assert.assertEquals("bc1447657931", billOrder.getBillNum());
Assert.assertEquals("你的订单标题", billOrder.getTitle());
Assert.assertEquals((Integer) 1, billOrder.getTotalFee());
Assert.assertEquals("UN", billOrder.getChannel());
Assert.assertEquals("UN_WEB", billOrder.getSubChannel());
Assert.assertFalse(billOrder.getPayResult());
Assert.assertFalse(billOrder.getRevertResult());
Assert.assertEquals((Long) 1447658025661L, billOrder.getCreatedTime());
Assert.assertEquals("{\"test\":\"willreturn\"}", billOrder.getOptional());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryRefundsAsyncNetworkError.
/**
* #2
* 测试response为400等网络异常
* @throws Exception
*/
@Test
public void testQueryRefundsAsyncNetworkError() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "wrong";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
query.queryRefundsAsync(BCReqParams.BCChannelTypes.ALL, null, null, null, null, 2, 10, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryRefundsResult);
BCQueryRefundsResult refundsResult = (BCQueryRefundsResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, refundsResult.getResultCode());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncTestMode.
/**
* #7
* test mode
* @throws Exception
*/
@Test
public void testQueryBillsAsyncTestMode() throws Exception {
BeeCloud.setSandbox(true);
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
// please note this content is fake, there should be content for bills, here delete the record for the limit of space
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"bills\":[{\"bill_no\":\"bc1447657931\"}]}";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
queryParams.channel = BCReqParams.BCChannelTypes.WX;
query.queryBillsAsync(queryParams, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryBillsResult);
BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
Assert.assertEquals((Integer) 0, billsResult.getResultCode());
Assert.assertEquals((int) billsResult.getCount(), billsResult.getBills().size());
BCBillOrder billOrder = billsResult.getBills().get(0);
Assert.assertEquals("bc1447657931", billOrder.getBillNum());
BeeCloud.setSandbox(false);
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryRefundByIDAsyncSucc.
/**
* #3
* 模拟response为200
* @throws Exception
*/
@Test
public void testQueryRefundByIDAsyncSucc() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"refund\":{\"result\":false,\"create_time\":1446531122439,\"refund_no\":\"2015110362316\",\"total_fee\":1,\"refund_fee\":1,\"channel\":\"WX\",\"bill_no\":\"ccd378d8823640a68e220949686e5922\",\"finish\":false,\"optional\":\"{\\\"test\\\":\\\"test\\\"}\",\"title\":\"demo测试\",\"sub_channel\":\"WX_NATIVE\",\"message_detail\":\"\"}}";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
query.queryRefundByIDAsync("refundid", new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryRefundResult);
BCQueryRefundResult refundResult = (BCQueryRefundResult) result;
Assert.assertEquals((Integer) 0, refundResult.getResultCode());
BCRefundOrder refundOrder = refundResult.getRefund();
Assert.assertEquals("ccd378d8823640a68e220949686e5922", refundOrder.getBillNum());
Assert.assertEquals("2015110362316", refundOrder.getRefundNum());
Assert.assertEquals("demo测试", refundOrder.getTitle());
Assert.assertEquals((Integer) 1, refundOrder.getTotalFee());
Assert.assertEquals((Integer) 1, refundOrder.getRefundFee());
Assert.assertEquals("WX", refundOrder.getChannel());
Assert.assertEquals("WX_NATIVE", refundOrder.getSubChannel());
Assert.assertFalse(refundOrder.isRefundFinished());
Assert.assertFalse(refundOrder.getRefundResult());
Assert.assertEquals((Long) 1446531122439L, refundOrder.getRefundCreatedTime());
Assert.assertEquals("{\"test\":\"test\"}", refundOrder.getOptional());
// 释放
latch.countDown();
}
});
// 等待
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations