Search in sources :

Example 16 with BCResult

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

the class BCQueryTest method testQueryBillByIDAsyncSucc.

/**
 * #3
 * 模拟response为200
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"pay\":{\"spay_result\":false,\"create_time\":1447643289722,\"total_fee\":1,\"channel\":\"WX\",\"trade_no\":\"\",\"bill_no\":\"20151116110810464\",\"optional\":\"{\\\"testkey1\\\":\\\"测试value值1\\\"}\",\"revert_result\":false,\"title\":\"安卓微信支付测试\",\"sub_channel\":\"WX_APP\",\"message_detail\":\"\",\"refund_result\":false},\"result_code\":0}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryBillByIDAsync("billid", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryBillResult);
            BCQueryBillResult billResult = (BCQueryBillResult) result;
            Assert.assertEquals((Integer) 0, billResult.getResultCode());
            BCBillOrder billOrder = billResult.getBill();
            Assert.assertEquals("20151116110810464", billOrder.getBillNum());
            Assert.assertEquals("安卓微信支付测试", billOrder.getTitle());
            Assert.assertTrue(billOrder.getTradeNum() == null || billOrder.getTradeNum().length() == 0);
            Assert.assertEquals((Integer) 1, billOrder.getTotalFee());
            Assert.assertEquals("WX", billOrder.getChannel());
            Assert.assertEquals("WX_APP", billOrder.getSubChannel());
            Assert.assertFalse(billOrder.getPayResult());
            Assert.assertFalse(billOrder.getRevertResult());
            Assert.assertEquals((Long) 1447643289722L, billOrder.getCreatedTime());
            Assert.assertEquals("{\"testkey1\":\"测试value值1\"}", billOrder.getOptional());
            // 释放
            latch.countDown();
        }
    });
    // 等待
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) BCBillOrder(cn.beecloud.entity.BCBillOrder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with BCResult

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

the class BCQueryTest method testQueryRefundStatusAsyncRefundNumInvalid.

/**
 * #2
 * 输入退款单号为null的情况
 * @throws Exception
 */
@Test
public void testQueryRefundStatusAsyncRefundNumInvalid() throws Exception {
    query.queryRefundStatusAsync(BCReqParams.BCChannelTypes.WX, null, new BCCallback() {

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

Example 18 with BCResult

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

the class BCQueryTest method testQueryOfflineBillStatusAsyncBillNumInvalid.

/**
 * #2
 * billNum为null的情况
 * @throws Exception
 */
@Test
public void testQueryOfflineBillStatusAsyncBillNumInvalid() throws Exception {
    query.queryOfflineBillStatusAsync(BCReqParams.BCChannelTypes.WX_SCAN, null, new BCCallback() {

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

Example 19 with BCResult

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

the class BCQueryTest method testQueryRefundStatusAsyncTestMode.

/**
 * #5
 * test mode
 * @throws Exception
 */
@Test
public void testQueryRefundStatusAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    query.queryRefundStatusAsync(BCReqParams.BCChannelTypes.WX, "refundnum", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCRefundStatus);
            BCRefundStatus status = (BCRefundStatus) result;
            Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, status.getResultCode());
            Assert.assertEquals("该功能暂不支持测试模式", status.getErrDetail());
            BeeCloud.setSandbox(false);
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCRefundStatus(cn.beecloud.entity.BCRefundStatus) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with BCResult

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

the class BCQueryTest method testQueryBillsCountAsyncNetworkError.

/**
 * #2
 * 网络请求400等异常情况
 * @throws Exception
 */
@Test
public void testQueryBillsCountAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    BCQuery.QueryParams params = new BCQuery.QueryParams();
    params.channel = BCReqParams.BCChannelTypes.ALL;
    query.queryBillsCountAsync(params, 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)

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