Search in sources :

Example 1 with BCQRCodeResult

use of cn.beecloud.entity.BCQRCodeResult 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 2 with BCQRCodeResult

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

the class BCOfflinePayTest method testReqQRCodeAsyncNetworkError.

/**
 * #2
 * 模拟网络400等异常
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // 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, 555, 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());
            // System.out.println(bcqrCodeResult.getErrDetail());
            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 3 with BCQRCodeResult

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

the class BCOfflinePayTest method testReqQRCodeAsyncSucc.

/**
 * #4
 * 模拟全部正常情况
 * @throws Exception
 */
@Test
public void testReqQRCodeAsyncSucc() 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.reqQRCodeAsync(BCReqParams.BCChannelTypes.WX_NATIVE, "订单标题", 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 4 with BCQRCodeResult

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

the class BCOfflinePayTest method testReqAliOfflineQRCodeAsync.

/**
 * 模拟直接通过reqAliOfflineQRCodeAsync请求支付宝二维码
 * @throws Exception
 */
@Test
public void testReqAliOfflineQRCodeAsync() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    pay.reqAliOfflineQRCodeAsync("订单标题", 1, "123456789ABCDE", null, Boolean.FALSE, 123, 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());
            // System.out.println(bcqrCodeResult.getErrDetail());
            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 5 with BCQRCodeResult

use of cn.beecloud.entity.BCQRCodeResult 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)8 BCResult (cn.beecloud.async.BCResult)8 BCQRCodeResult (cn.beecloud.entity.BCQRCodeResult)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Bitmap (android.graphics.Bitmap)2 Looper (android.os.Looper)2 CountDownLatch (java.util.concurrent.CountDownLatch)1