Search in sources :

Example 11 with BCCallback

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

the class BCOfflinePayTest method testReqOfflinePayAsyncErrorFromServer.

/**
 * #3
 * 测试网络200 但是 支付不成功
 * @throws Exception
 */
@Test
public void testReqOfflinePayAsyncErrorFromServer() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"CHANNEL_ERROR\",\"err_detail\":\"AUTHCODEEXPIRE\",\"result_code\":7,\"pay_result\":false}";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, "storeid", 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) 7, payResult.getErrCode());
            Assert.assertEquals("CHANNEL_ERROR", payResult.getErrMsg());
            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)

Example 12 with BCCallback

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

the class BCQueryTest method testQueryBillByIDAsyncTestMode.

/**
 * #4
 * test mode
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    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());
            BeeCloud.setSandbox(false);
            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 13 with BCCallback

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

the class BCQueryTest method testQueryOfflineBillStatusAsyncNetworkError.

/**
 * #3
 * 网络请求400等异常情况
 * @throws Exception
 */
@Test
public void testQueryOfflineBillStatusAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    query.queryOfflineBillStatusAsync(BCReqParams.BCChannelTypes.WX_SCAN, "fakeid", 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 14 with BCCallback

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

the class BCQueryTest method testQueryBillsCountAsyncSucc.

/**
 * #3
 * 网络请求200
 * @throws Exception
 */
@Test
public void testQueryBillsCountAsyncSucc() 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);
    BCQuery.QueryParams params = new BCQuery.QueryParams();
    params.channel = BCReqParams.BCChannelTypes.ALL;
    params.payResult = Boolean.TRUE;
    query.queryBillsCountAsync(params, 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) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with BCCallback

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

the class BCQueryTest method testQueryBillByIDAsyncParamInvalid.

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

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

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