Search in sources :

Example 1 with BCPayResult

use of cn.beecloud.entity.BCPayResult 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 BCPayResult

use of cn.beecloud.entity.BCPayResult 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 3 with BCPayResult

use of cn.beecloud.entity.BCPayResult 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);
}
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 4 with BCPayResult

use of cn.beecloud.entity.BCPayResult 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);
}
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 BCPayResult

use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.

the class BCOfflinePayTest method testReqOfflinePayAsyncErrorFromServer.

/**
 * #3
 * 测试网络200 但是 支付不成功
 * @throws Exception
 */
@Test
public void testReqOfflinePayAsyncErrorFromServer() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"CHANNEL_ERROR\",\"err_detail\":\"AUTHCODEEXPIRE\",\"result_code\":7,\"pay_result\":false}";
    // 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_FAIL, payResult.getResult());
            Assert.assertEquals((Integer) 7, payResult.getErrCode());
            Assert.assertEquals("CHANNEL_ERROR", payResult.getErrMsg());
            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)

Aggregations

BCPayResult (cn.beecloud.entity.BCPayResult)20 BCCallback (cn.beecloud.async.BCCallback)10 BCResult (cn.beecloud.async.BCResult)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 HashMap (java.util.HashMap)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 BCReqParams (cn.beecloud.entity.BCReqParams)2 Gson (com.google.gson.Gson)2 Type (java.lang.reflect.Type)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ProgressDialog (android.app.ProgressDialog)1 View (android.view.View)1 TextView (android.widget.TextView)1 BCPayReqParams (cn.beecloud.entity.BCPayReqParams)1 BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)1 BCQueryReqParams (cn.beecloud.entity.BCQueryReqParams)1 PayTask (com.alipay.sdk.app.PayTask)1 PayCallBack (com.baidu.android.pay.PayCallBack)1