Search in sources :

Example 46 with BCCallback

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

the class BCQueryTest method testQueryBillByIDAsyncNetworkError.

/**
 * #2
 * 模拟网络异常response为400等
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncNetworkError() 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);
    query.queryBillByIDAsync("billid", new BCCallback() {

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

Example 47 with BCCallback

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

the class BCQueryTest method testQueryRefundsAsyncByChannelBillRefundNum.

/**
 * #5
 * 测试根据支付渠道和(支付订单号|退款单号)获取退款订单列表
 * @throws Exception
 */
@Test
public void testQueryRefundsAsyncByChannelBillRefundNum() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    // please note this content is fake, there should be content for refunds, here delete the record for the limit of space
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"refunds\":[{\"refund_no\":\"201511141447430832000\"}]}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryRefundsAsync(BCReqParams.BCChannelTypes.ALL, "billnum", "refundnum", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryRefundsResult);
            BCQueryRefundsResult refundsResult = (BCQueryRefundsResult) result;
            Assert.assertEquals((Integer) 0, refundsResult.getResultCode());
            Assert.assertEquals((int) refundsResult.getCount(), refundsResult.getRefunds().size());
            BCRefundOrder refundOrder = refundsResult.getRefunds().get(0);
            Assert.assertEquals("201511141447430832000", refundOrder.getRefundNum());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCRefundOrder(cn.beecloud.entity.BCRefundOrder) BCQueryRefundsResult(cn.beecloud.entity.BCQueryRefundsResult) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with BCCallback

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

the class BCQueryTest method testQueryOfflineBillStatusAsyncSucc.

/**
 * #4
 * 模拟请求成功的情况
 * @throws Exception
 */
@Test
public void testQueryOfflineBillStatusAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"submit_msg\":\"OK\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"did_submit\":true,\"pay_result\":true}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    query.queryOfflineBillStatusAsync(BCReqParams.BCChannelTypes.WX_NATIVE, "fakeid", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCBillStatus);
            BCBillStatus status = (BCBillStatus) result;
            Assert.assertEquals((Integer) 0, status.getResultCode());
            Assert.assertTrue(status.getPayResult());
            // 释放
            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 49 with BCCallback

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

the class BCQueryTest method testQueryRefundsCountAsyncSucc.

/**
 * #3
 * 网络请求200
 * @throws Exception
 */
@Test
public void testQueryRefundsCountAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"count\":826,\"result_code\":0}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
    BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
    queryParams.channel = BCReqParams.BCChannelTypes.WX;
    queryParams.startTime = sdf.parse("2015-10-01 00:00").getTime();
    query.queryRefundsCountAsync(queryParams, new BCCallback() {

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

Example 50 with BCCallback

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

the class BCQueryTest method testQueryRefundsCountAsyncTestMode.

/**
 * #4
 * test mode
 * @throws Exception
 */
@Test
public void testQueryRefundsCountAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
    queryParams.channel = BCReqParams.BCChannelTypes.WX;
    query.queryRefundsCountAsync(queryParams, 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());
            Assert.assertEquals("该功能暂不支持测试模式", countResult.getErrDetail());
            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