use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCOfflinePayTest method testReqQRCodeAsyncNetworkError.
/**
* #2
* 模拟网络400等异常
* @throws Exception
*/
@Test
public void testReqQRCodeAsyncNetworkError() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "wrong";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqQRCodeAsync(BCReqParams.BCChannelTypes.WX_NATIVE, "订单标题", 1, "123456789ABCDE", null, Boolean.FALSE, 555, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQRCodeResult);
BCQRCodeResult bcqrCodeResult = (BCQRCodeResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, bcqrCodeResult.getResultCode());
// System.out.println(bcqrCodeResult.getErrDetail());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCOfflinePayTest method testReqQRCodeAsyncSucc.
/**
* #4
* 模拟全部正常情况
* @throws Exception
*/
@Test
public void testReqQRCodeAsyncSucc() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"OK\",\"code_url\":\"weixin://wxpay/bizpayurl?pr=ESDN0qd\",\"err_detail\":\"\",\"result_code\":0}";
// mock as junit does not provide real android sdk
PowerMockito.stub(PowerMockito.method(Looper.class, "myLooper")).toReturn(PowerMockito.mock(Looper.class));
PowerMockito.stub(PowerMockito.method(Looper.class, "getMainLooper")).toReturn(PowerMockito.mock(Looper.class));
PowerMockito.stub(PowerMockito.method(Bitmap.class, "createBitmap", int.class, int.class, Bitmap.Config.class)).toReturn(PowerMockito.mock(Bitmap.class));
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqQRCodeAsync(BCReqParams.BCChannelTypes.WX_NATIVE, "订单标题", 1, "123456789ABCDE", null, Boolean.TRUE, null, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQRCodeResult);
BCQRCodeResult bcqrCodeResult = (BCQRCodeResult) result;
Assert.assertEquals((Integer) 0, bcqrCodeResult.getResultCode());
Assert.assertEquals("weixin://wxpay/bizpayurl?pr=ESDN0qd", bcqrCodeResult.getQrCodeRawContent());
Assert.assertEquals(BCQRCodeResult.DEFAULT_QRCODE_WIDTH, bcqrCodeResult.getQrCodeWidth());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncByBean.
/**
* #5
* 测试通过PayParams支付
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncByBean() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"pay_result\":true}";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
BCOfflinePay.PayParams params = new BCOfflinePay.PayParams();
params.channelType = BCReqParams.BCChannelTypes.WX_SCAN;
params.billTitle = "订单标题";
params.billTotalFee = 1;
params.billNum = "123456789ABCDE";
params.authCode = "fakecode";
pay.reqOfflinePayAsync(params, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_SUCCESS, payResult.getResult());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncTestMode.
/**
* #6
* 模拟test mode,应该提示暂不支持
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncTestMode() throws Exception {
BeeCloud.setSandbox(true);
pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", 1, "123456789abcde", null, "authcode", "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());
Assert.assertEquals("该功能暂不支持测试模式", payResult.getDetailInfo());
BeeCloud.setSandbox(false);
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.async.BCCallback in project ttdj by soonphe.
the class BCOfflinePayTest method testReqAliOfflineQRCodeAsync.
/**
* 模拟直接通过reqAliOfflineQRCodeAsync请求支付宝二维码
* @throws Exception
*/
@Test
public void testReqAliOfflineQRCodeAsync() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "wrong";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqAliOfflineQRCodeAsync("订单标题", 1, "123456789ABCDE", null, Boolean.FALSE, 123, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQRCodeResult);
BCQRCodeResult bcqrCodeResult = (BCQRCodeResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, bcqrCodeResult.getResultCode());
// System.out.println(bcqrCodeResult.getErrDetail());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations