use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryRefundStatusAsyncNetworkError.
/**
* #3
* 网络请求400等异常情况
* @throws Exception
*/
@Test
public void testQueryRefundStatusAsyncNetworkError() 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.queryRefundStatusAsync(BCReqParams.BCChannelTypes.WX, "refundnum", new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCRefundStatus);
BCRefundStatus status = (BCRefundStatus) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, status.getResultCode());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncByChannel.
/**
* #4
* 测试根据支付渠道获取订单
* @throws Exception
*/
@Test
public void testQueryBillsAsyncByChannel() throws Exception {
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);
query.queryBillsAsync(BCReqParams.BCChannelTypes.ALL, 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());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryRefundsAsyncByBean.
/**
* #6
* 测试根据BCQuery.QueryParams获取退款订单列表
* @throws Exception
*/
@Test
public void testQueryRefundsAsyncByBean() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
// please note this content is fake, there should be content for refunds, here delete the record for the limit of space
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"refunds\":[{\"refund_no\":\"201511141447430832000\"}]}";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
queryParams.channel = BCReqParams.BCChannelTypes.UN;
queryParams.refundNum = "refundnum";
queryParams.billNum = "billnum";
query.queryRefundsAsync(queryParams, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryRefundsResult);
BCQueryRefundsResult refundsResult = (BCQueryRefundsResult) result;
Assert.assertEquals((Integer) 0, refundsResult.getResultCode());
Assert.assertEquals((int) refundsResult.getCount(), refundsResult.getRefunds().size());
BCRefundOrder refundOrder = refundsResult.getRefunds().get(0);
Assert.assertEquals("201511141447430832000", refundOrder.getRefundNum());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsCountAsyncChannelInvalid.
/**
* #1
* 测试channel为null
* @throws Exception
*/
@Test
public void testQueryBillsCountAsyncChannelInvalid() throws Exception {
BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
queryParams.channel = null;
query.queryBillsCountAsync(queryParams, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryCountResult);
BCQueryCountResult countResult = (BCQueryCountResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, countResult.getResultCode());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCResult in project ttdj by soonphe.
the class BCPayTest method testReqPaymentAsyncNetworkError.
/**
* #2
* 模拟网络400等异常
* @throws Exception
*/
@Test
public void testReqPaymentAsyncNetworkError() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "mocked";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
// prepare params
final BCPay.PayParams payParams = new BCPay.PayParams();
payParams.channelType = BCReqParams.BCChannelTypes.WX_APP;
payParams.billTitle = "正常title";
payParams.billTotalFee = 3;
payParams.billNum = "123456789ABCDE";
pay.reqPaymentAsync(payParams, 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_EXCEPTION_ERR_CODE, payResult.getErrCode());
Assert.assertEquals(BCPayResult.FAIL_EXCEPTION, payResult.getErrMsg());
// System.out.println(payResult.getDetailInfo());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations