use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCPayTest method testReqPaymentAsyncErrorFromServer.
/**
* #3
* 模拟网络200 但是存在后台参数配置问题导致的错误
* @throws Exception
*/
@Test
public void testReqPaymentAsyncErrorFromServer() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"PAY_FACTOR_NOT_SET\",\"err_detail\":\"支付宝参数: partner, seller_id, RSA密钥未配置\",\"result_code\":2}";
// 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";
Map<String, String> analysis = new HashMap<String, String>();
analysis.put("category", "en");
payParams.analysis = analysis;
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) 2, payResult.getErrCode());
Assert.assertEquals("PAY_FACTOR_NOT_SET", payResult.getErrMsg());
Assert.assertEquals("支付宝参数: partner, seller_id, RSA密钥未配置", payResult.getDetailInfo());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations