Search in sources :

Example 61 with BCResult

use of cn.beecloud.async.BCResult 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);
}
Also used : HashMap(java.util.HashMap) BCCallback(cn.beecloud.async.BCCallback) BCPayResult(cn.beecloud.entity.BCPayResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BCCallback (cn.beecloud.async.BCCallback)61 BCResult (cn.beecloud.async.BCResult)61 Test (org.junit.Test)61 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)61 BCPayResult (cn.beecloud.entity.BCPayResult)10 BCQRCodeResult (cn.beecloud.entity.BCQRCodeResult)8 BCBillOrder (cn.beecloud.entity.BCBillOrder)7 BCQueryBillsResult (cn.beecloud.entity.BCQueryBillsResult)7 BCQueryCountResult (cn.beecloud.entity.BCQueryCountResult)7 BCQueryRefundsResult (cn.beecloud.entity.BCQueryRefundsResult)7 BCBillStatus (cn.beecloud.entity.BCBillStatus)5 BCRefundOrder (cn.beecloud.entity.BCRefundOrder)5 BCRefundStatus (cn.beecloud.entity.BCRefundStatus)5 BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)4 BCQueryRefundResult (cn.beecloud.entity.BCQueryRefundResult)4 BCRevertStatus (cn.beecloud.entity.BCRevertStatus)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 BCReqParams (cn.beecloud.entity.BCReqParams)3 Bitmap (android.graphics.Bitmap)2 Looper (android.os.Looper)2