Search in sources :

Example 36 with BCResult

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

the class BCOfflinePayTest method testReqRevertBillAsyncSucc.

/**
 * #3
 * 模拟全部正常的情况
 * @throws Exception
 */
@Test
public void testReqRevertBillAsyncSucc() throws Exception {
    BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"Success\",\"result_code\":0,\"revert_status\":true}";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    pay.reqRevertBillAsync(BCReqParams.BCChannelTypes.ALI_OFFLINE_QRCODE, "fakebillnum", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCRevertStatus);
            BCRevertStatus revertStatus = (BCRevertStatus) result;
            Assert.assertEquals((Integer) 0, revertStatus.getResultCode());
            Assert.assertTrue(revertStatus.getRevertStatus());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCRevertStatus(cn.beecloud.entity.BCRevertStatus) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with BCResult

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

the class BCOfflinePayTest method testReqRevertBillAsyncParamInvalid.

/**
 * #1
 * 模拟参数问题
 * @throws Exception
 */
@Test
public void testReqRevertBillAsyncParamInvalid() throws Exception {
    Object[][] test = new Object[][] { // 依次代表渠道类型 订单流水号
    new Object[] { null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_APP, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, null } };
    for (Object[] objects : test) {
        final CountDownLatch localLatch = new CountDownLatch(1);
        pay.reqRevertBillAsync((BCReqParams.BCChannelTypes) objects[0], (String) objects[1], new BCCallback() {

            @Override
            public void done(BCResult result) {
                Assert.assertTrue(result instanceof BCRevertStatus);
                BCRevertStatus revertStatus = (BCRevertStatus) result;
                Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, revertStatus.getResultCode());
                // System.out.println(revertStatus.getErrDetail());
                localLatch.countDown();
            }
        });
        localLatch.await(2000, TimeUnit.MILLISECONDS);
    }
}
Also used : BCReqParams(cn.beecloud.entity.BCReqParams) BCCallback(cn.beecloud.async.BCCallback) BCRevertStatus(cn.beecloud.entity.BCRevertStatus) CountDownLatch(java.util.concurrent.CountDownLatch) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with BCResult

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

the class BCOfflinePayTest method testReqWXNativeQRCodeAsync.

/**
 * 模拟直接通过reqWXNativeQRCodeAsync请求微信二维码
 * @throws Exception
 */
@Test
public void testReqWXNativeQRCodeAsync() 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.reqWXNativeQRCodeAsync("订单标题", 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);
}
Also used : Looper(android.os.Looper) Bitmap(android.graphics.Bitmap) BCCallback(cn.beecloud.async.BCCallback) BCQRCodeResult(cn.beecloud.entity.BCQRCodeResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 39 with BCResult

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

the class BCOfflinePayTest method testReqQRCodeAsyncTestMode.

/**
 * #6
 * 模拟测试模式,应该提示暂不支持
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    pay.reqQRCodeAsync(BCReqParams.BCChannelTypes.ALI_OFFLINE_QRCODE, "billtitle", 1, "billnum", 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.assertEquals("该功能暂不支持测试模式", bcqrCodeResult.getErrDetail());
            // revert back
            BeeCloud.setSandbox(false);
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCQRCodeResult(cn.beecloud.entity.BCQRCodeResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with BCResult

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

the class BCOfflinePayTest method testReqQRCodeAsyncByBean.

/**
 * #5
 * 模拟PayParams方式发起的请求
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncByBean() 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 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_NATIVE;
    params.billTitle = "订单标题";
    params.billTotalFee = 1;
    params.billNum = "123456789ABCDE";
    params.genQRCode = Boolean.FALSE;
    pay.reqQRCodeAsync(params, 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(null, bcqrCodeResult.getQrCodeBitmap());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) 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