Search in sources :

Example 1 with BCResult

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

the class BCOfflinePayTest method testReqOfflinePayAsyncSucc.

/**
 * #4
 * 测试全部正常的情况
 * @throws Exception
 */
@Test
public void testReqOfflinePayAsyncSucc() 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);
    pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, "storeid", 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);
}
Also used : 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 2 with BCResult

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

the class BCOfflinePayTest method testReqRevertBillAsyncTestMode.

/**
 * #4
 * test mode暂不支持
 * @throws Exception
 */
@Test
public void testReqRevertBillAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    pay.reqRevertBillAsync(BCReqParams.BCChannelTypes.ALI_SCAN, "billnum", 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());
            Assert.assertEquals("该功能暂不支持测试模式", revertStatus.getErrDetail());
            BeeCloud.setSandbox(false);
            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 3 with BCResult

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

the class BCOfflinePayTest method testReqQRCodeAsyncErrorFromServer.

/**
 * #3
 * 模拟网络正常,参数异常
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncErrorFromServer() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"RUNTIME_ERORR\",\"err_detail\":\"未知错误,请联系BeeCloud\",\"result_code\":16}";
    // 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, 321, new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQRCodeResult);
            BCQRCodeResult bcqrCodeResult = (BCQRCodeResult) result;
            Assert.assertEquals((Integer) 16, bcqrCodeResult.getResultCode());
            Assert.assertEquals("RUNTIME_ERORR", bcqrCodeResult.getResultMsg());
            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 4 with BCResult

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

the class BCOfflinePayTest method testReqOfflinePayAsyncNetworkError.

/**
 * #2
 * 测试网络400异常情况
 * @throws Exception
 */
@Test
public void testReqOfflinePayAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, 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_EXCEPTION_ERR_CODE, payResult.getErrCode());
            Assert.assertEquals(BCPayResult.FAIL_EXCEPTION, payResult.getErrMsg());
            // System.out.println(payResult.getDetailInfo());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : 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 5 with BCResult

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

the class BCOfflinePayTest method testReqRevertBillAsyncNetworkError.

/**
 * #2
 * 模拟网络400等异常
 * @throws Exception
 */
@Test
public void testReqRevertBillAsyncNetworkError() throws Exception {
    BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    pay.reqRevertBillAsync(BCReqParams.BCChannelTypes.WX_SCAN, "fakebillnum", 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());
            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)

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