Search in sources :

Example 31 with BCResult

use of cn.beecloud.async.BCResult in project ttdj by soonphe.

the class BCQueryTest method testQueryRefundsCountAsyncChannelInvalid.

/**
 * #1
 * 测试channel为null
 * @throws Exception
 */
@Test
public void testQueryRefundsCountAsyncChannelInvalid() throws Exception {
    BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
    queryParams.channel = null;
    query.queryRefundsCountAsync(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);
}
Also used : BCQueryCountResult(cn.beecloud.entity.BCQueryCountResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with BCResult

use of cn.beecloud.async.BCResult in project ttdj by soonphe.

the class BCQueryTest method testQueryRefundsAsyncChannelNull.

/**
 * #1
 * 测试没有传channel的情况
 * @throws Exception
 */
@Test
public void testQueryRefundsAsyncChannelNull() throws Exception {
    query.queryRefundsAsync(null, null, null, null, null, null, null, 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();
        }
    });
    // 最多等2s
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCQueryRefundsResult(cn.beecloud.entity.BCQueryRefundsResult) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with BCResult

use of cn.beecloud.async.BCResult in project ttdj by soonphe.

the class BCPayTest method testReqPaymentAsyncParamsInvalid.

/**
 * #1
 * 测试参数错误
 * @throws Exception
 */
@Test
public void testReqPaymentAsyncParamsInvalid() throws Exception {
    Object[][] test = new Object[][] { // 依次对应必填参数 渠道类型 订单标题 订单金额 订单流水号
    new Object[] { BCReqParams.BCChannelTypes.JD_WAP, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.WX_APP, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_APP, "试一个很长的title--参数公共返回参数取值及含义参见支付公共返回参数部分", null, null }, new Object[] { BCReqParams.BCChannelTypes.UN_APP, "正常title", null, null }, new Object[] { BCReqParams.BCChannelTypes.BD_APP, "正常title", -1, null } };
    for (Object[] objects : test) {
        BCPay.PayParams payParams = new BCPay.PayParams();
        payParams.channelType = (BCReqParams.BCChannelTypes) objects[0];
        payParams.billTitle = (String) objects[1];
        payParams.billTotalFee = (Integer) objects[2];
        payParams.billNum = (String) objects[3];
        final CountDownLatch localLatch = new CountDownLatch(1);
        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());
                // 渠道错误由BCException抛出,其他正常参数异常错误
                Assert.assertTrue(payResult.getErrCode() == BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE || payResult.getErrCode() == BCPayResult.APP_INTERNAL_PARAMS_ERR_CODE);
                Assert.assertTrue(payResult.getErrMsg().equals(BCPayResult.FAIL_EXCEPTION) || payResult.getErrMsg().equals(BCPayResult.FAIL_INVALID_PARAMS));
                // System.out.println(payResult.getDetailInfo());
                localLatch.countDown();
            }
        });
        localLatch.await(2000, TimeUnit.MILLISECONDS);
    }
}
Also used : BCReqParams(cn.beecloud.entity.BCReqParams) BCCallback(cn.beecloud.async.BCCallback) CountDownLatch(java.util.concurrent.CountDownLatch) BCPayResult(cn.beecloud.entity.BCPayResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with BCResult

use of cn.beecloud.async.BCResult in project ttdj by soonphe.

the class BCPayTest method testReqWXPaymentAsync.

/**
 * 模拟微信发起支付
 * @throws Exception
 */
@Test
public void testReqWXPaymentAsync() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"nonce_str\":\"20151119114011235\",\"package\":\"Sign=WXPay\",\"resultCode\":0,\"errMsg\":\"OK:\",\"prepay_id\":\"wx20151119114008765ce0ad440384384408\",\"result_msg\":\"OK\",\"partner_id\":\"1240421502\",\"err_detail\":\"\",\"result_code\":0,\"id\":\"ff5fef0c-93bd-46d2-8500-5ed53502d344\",\"app_id\":\"wxf1aa465362b4c8f1\",\"pay_sign\":\"D0F8E79A14731B59CE04B634FD588C35\",\"timestamp\":\"1447904408\"}";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    Map<String, String> optional = new HashMap<String, String>();
    optional.put("aya", "啊呀");
    pay.reqWXPaymentAsync("正常title", 22, "123456789ABCDE", optional, 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());
            Assert.assertTrue(payResult.getDetailInfo().startsWith("Error: 微信API为空"));
            System.out.println(payResult.getDetailInfo());
            Assert.assertEquals("ff5fef0c-93bd-46d2-8500-5ed53502d344", BCCache.getInstance().billID);
            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)

Example 35 with BCResult

use of cn.beecloud.async.BCResult in project ttdj by soonphe.

the class BCOfflinePayTest method testReqQRCodeAsyncParamInvalid.

/**
 * #1
 * 模拟参数不合理
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncParamInvalid() throws Exception {
    // 依次对应必填参数 订单标题 订单金额 订单流水号
    Object[][] test = new Object[][] { new Object[] { null, null, null }, new Object[] { "试一个很长的title--参数公共返回参数取值及含义参见支付公共返回参数部分", null, null }, new Object[] { "正常title", null, null }, new Object[] { "正常title", -1, null }, new Object[] { "正常title", 3, null }, new Object[] { "正常title", 3, "123" } };
    for (Object[] objects : test) {
        final CountDownLatch localLatch = new CountDownLatch(1);
        pay.reqQRCodeAsync(BCReqParams.BCChannelTypes.ALI_OFFLINE_QRCODE, (String) objects[0], (Integer) objects[1], (String) objects[2], null, Boolean.FALSE, 333, 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());
                Assert.assertTrue(bcqrCodeResult.getErrDetail().startsWith("parameters"));
                // System.out.println(bcqrCodeResult.getErrDetail());
                localLatch.countDown();
            }
        });
        // 最多等待2s
        localLatch.await(2000, TimeUnit.MILLISECONDS);
    }
}
Also used : BCCallback(cn.beecloud.async.BCCallback) CountDownLatch(java.util.concurrent.CountDownLatch) BCQRCodeResult(cn.beecloud.entity.BCQRCodeResult) 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