Search in sources :

Example 51 with BCResult

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

the class BCQueryTest method testQueryRefundsAsyncSucc.

/**
 * #3
 * 正常response为200的情况
 * @throws Exception
 */
@Test
public void testQueryRefundsAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    // please note this content is fake, there should be more content for refunds, here just keep one record for the limit of space
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"refunds\":[{\"result\":false,\"create_time\":1447430833318,\"refund_no\":\"201511141447430832000\",\"total_fee\":1,\"refund_fee\":1,\"channel\":\"WX\",\"bill_no\":\"20151113132244266\",\"finish\":false,\"optional\":\"\",\"title\":\"2015-10-21 Release\",\"sub_channel\":\"WX_APP\"}]}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryRefundsAsync(BCReqParams.BCChannelTypes.ALL, null, null, null, null, 2, 10, new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryRefundsResult);
            BCQueryRefundsResult refundsResult = (BCQueryRefundsResult) result;
            Assert.assertEquals((Integer) 0, refundsResult.getResultCode());
            Assert.assertTrue(refundsResult.getCount() == refundsResult.getRefunds().size());
            BCRefundOrder refundOrder = refundsResult.getRefunds().get(0);
            Assert.assertEquals("20151113132244266", refundOrder.getBillNum());
            Assert.assertEquals("201511141447430832000", refundOrder.getRefundNum());
            Assert.assertEquals("2015-10-21 Release", refundOrder.getTitle());
            Assert.assertEquals((Integer) 1, refundOrder.getTotalFee());
            Assert.assertEquals((Integer) 1, refundOrder.getRefundFee());
            Assert.assertEquals("WX", refundOrder.getChannel());
            Assert.assertEquals("WX_APP", refundOrder.getSubChannel());
            Assert.assertFalse(refundOrder.isRefundFinished());
            Assert.assertFalse(refundOrder.getRefundResult());
            Assert.assertEquals((Long) 1447430833318L, refundOrder.getRefundCreatedTime());
            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 52 with BCResult

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

the class BCQueryTest method testQueryRefundByIDAsyncNetworkError.

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

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

Example 53 with BCResult

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

the class BCQueryTest method testQueryRefundByIDAsyncTestMode.

/**
 * #4
 * test mode
 * @throws Exception
 */
@Test
public void testQueryRefundByIDAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    query.queryRefundByIDAsync("refundid", new BCCallback() {

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

Example 54 with BCResult

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

the class BCQueryTest method testQueryRefundsAsyncByChannel.

/**
 * #4
 * 测试根据支付渠道获取退款订单
 * @throws Exception
 */
@Test
public void testQueryRefundsAsyncByChannel() 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, 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 55 with BCResult

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

the class BCQueryTest method testQueryRefundStatusAsyncSucc.

/**
 * #4
 * 网络请求200
 * @throws Exception
 */
@Test
public void testQueryRefundStatusAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"refund_status\":\"SUCCESS\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    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((Integer) 0, status.getResultCode());
            Assert.assertTrue(BCRefundStatus.RefundStatus.REFUND_STATUS_SUCCESS.equals(status.getRefundStatus()));
            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)

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