Search in sources :

Example 1 with BCQueryRefundResult

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

the class BCQueryTest method testQueryRefundByIDAsyncParamInvalid.

/**
 * #1
 * 测试传入id为null的情况
 * @throws Exception
 */
@Test
public void testQueryRefundByIDAsyncParamInvalid() throws Exception {
    query.queryRefundByIDAsync(null, new BCCallback() {

        @Override
        public void done(BCResult result) {
            // 传出的应是BCQueryRefundResult类型
            Assert.assertTrue(result instanceof BCQueryRefundResult);
            BCQueryRefundResult refundResult = (BCQueryRefundResult) result;
            // 返回的结果应该是-1
            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 2 with BCQueryRefundResult

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

the class BCQueryTest method testQueryRefundByIDAsyncSucc.

/**
 * #3
 * 模拟response为200
 * @throws Exception
 */
@Test
public void testQueryRefundByIDAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"refund\":{\"result\":false,\"create_time\":1446531122439,\"refund_no\":\"2015110362316\",\"total_fee\":1,\"refund_fee\":1,\"channel\":\"WX\",\"bill_no\":\"ccd378d8823640a68e220949686e5922\",\"finish\":false,\"optional\":\"{\\\"test\\\":\\\"test\\\"}\",\"title\":\"demo测试\",\"sub_channel\":\"WX_NATIVE\",\"message_detail\":\"\"}}";
    // 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((Integer) 0, refundResult.getResultCode());
            BCRefundOrder refundOrder = refundResult.getRefund();
            Assert.assertEquals("ccd378d8823640a68e220949686e5922", refundOrder.getBillNum());
            Assert.assertEquals("2015110362316", refundOrder.getRefundNum());
            Assert.assertEquals("demo测试", refundOrder.getTitle());
            Assert.assertEquals((Integer) 1, refundOrder.getTotalFee());
            Assert.assertEquals((Integer) 1, refundOrder.getRefundFee());
            Assert.assertEquals("WX", refundOrder.getChannel());
            Assert.assertEquals("WX_NATIVE", refundOrder.getSubChannel());
            Assert.assertFalse(refundOrder.isRefundFinished());
            Assert.assertFalse(refundOrder.getRefundResult());
            Assert.assertEquals((Long) 1446531122439L, refundOrder.getRefundCreatedTime());
            Assert.assertEquals("{\"test\":\"test\"}", refundOrder.getOptional());
            // 释放
            latch.countDown();
        }
    });
    // 等待
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCQueryRefundResult(cn.beecloud.entity.BCQueryRefundResult) BCRefundOrder(cn.beecloud.entity.BCRefundOrder) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BCQueryRefundResult

use of cn.beecloud.entity.BCQueryRefundResult 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 4 with BCQueryRefundResult

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

Aggregations

BCCallback (cn.beecloud.async.BCCallback)4 BCResult (cn.beecloud.async.BCResult)4 BCQueryRefundResult (cn.beecloud.entity.BCQueryRefundResult)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 BCRefundOrder (cn.beecloud.entity.BCRefundOrder)1