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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations