Search in sources :

Example 56 with BCCallback

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

the class BCQueryTest method testQueryRefundStatusAsyncNetworkError.

/**
 * #3
 * 网络请求400等异常情况
 * @throws Exception
 */
@Test
public void testQueryRefundStatusAsyncNetworkError() 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.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());
            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 57 with BCCallback

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

the class BCQueryTest method testQueryBillsAsyncByChannel.

/**
 * #4
 * 测试根据支付渠道获取订单
 * @throws Exception
 */
@Test
public void testQueryBillsAsyncByChannel() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    // please note this content is fake, there should be content for bills, here delete the record for the limit of space
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"bills\":[{\"bill_no\":\"bc1447657931\"}]}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryBillsAsync(BCReqParams.BCChannelTypes.ALL, new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryBillsResult);
            BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
            Assert.assertEquals((Integer) 0, billsResult.getResultCode());
            Assert.assertEquals((int) billsResult.getCount(), billsResult.getBills().size());
            BCBillOrder billOrder = billsResult.getBills().get(0);
            Assert.assertEquals("bc1447657931", billOrder.getBillNum());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillsResult(cn.beecloud.entity.BCQueryBillsResult) 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 58 with BCCallback

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

the class BCQueryTest method testQueryRefundsAsyncByBean.

/**
 * #6
 * 测试根据BCQuery.QueryParams获取退款订单列表
 * @throws Exception
 */
@Test
public void testQueryRefundsAsyncByBean() 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);
    BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
    queryParams.channel = BCReqParams.BCChannelTypes.UN;
    queryParams.refundNum = "refundnum";
    queryParams.billNum = "billnum";
    query.queryRefundsAsync(queryParams, 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 59 with BCCallback

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

the class BCQueryTest method testQueryBillsCountAsyncChannelInvalid.

/**
 * #1
 * 测试channel为null
 * @throws Exception
 */
@Test
public void testQueryBillsCountAsyncChannelInvalid() throws Exception {
    BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
    queryParams.channel = null;
    query.queryBillsCountAsync(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());
            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)

Example 60 with BCCallback

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

the class BCPayTest method testReqPaymentAsyncNetworkError.

/**
 * #2
 * 模拟网络400等异常
 * @throws Exception
 */
@Test
public void testReqPaymentAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "mocked";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    // prepare params
    final BCPay.PayParams payParams = new BCPay.PayParams();
    payParams.channelType = BCReqParams.BCChannelTypes.WX_APP;
    payParams.billTitle = "正常title";
    payParams.billTotalFee = 3;
    payParams.billNum = "123456789ABCDE";
    pay.reqPaymentAsync(payParams, new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCPayResult);
            BCPayResult payResult = (BCPayResult) result;
            Assert.assertEquals(BCPayResult.RESULT_FAIL, payResult.getResult());
            Assert.assertEquals((Integer) BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE, payResult.getErrCode());
            Assert.assertEquals(BCPayResult.FAIL_EXCEPTION, payResult.getErrMsg());
            // System.out.println(payResult.getDetailInfo());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCCallback(cn.beecloud.async.BCCallback) BCPayResult(cn.beecloud.entity.BCPayResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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