use of cn.beecloud.entity.BCQueryBillsResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncNetworkError.
/**
* #2
* 测试response为400等网络异常
* @throws Exception
*/
@Test
public void testQueryBillsAsyncNetworkError() 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.queryBillsAsync(BCReqParams.BCChannelTypes.ALL, null, null, null, 2, 10, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryBillsResult);
BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billsResult.getResultCode());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCQueryBillsResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncChannelNull.
/**
* #1
* 测试没有传channel的情况
* @throws Exception
*/
@Test
public void testQueryBillsAsyncChannelNull() throws Exception {
query.queryBillsAsync(null, null, null, null, null, null, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryBillsResult);
BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billsResult.getResultCode());
latch.countDown();
}
});
// 最多等2s
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCQueryBillsResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncByChannelBillNum.
/**
* #5
* 测试根据支付渠道和订单号获取订单
* @throws Exception
*/
@Test
public void testQueryBillsAsyncByChannelBillNum() 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, "billnum", 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);
}
use of cn.beecloud.entity.BCQueryBillsResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncByBean.
/**
* #6
* 测试通过BCQuery.QueryParams方式获取订单
* @throws Exception
*/
@Test
public void testQueryBillsAsyncByBean() 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);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
BCQuery.QueryParams queryParams = new BCQuery.QueryParams();
queryParams.channel = BCReqParams.BCChannelTypes.WX;
queryParams.startTime = sdf.parse("2015-10-01 00:00").getTime();
query.queryBillsAsync(queryParams, 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);
}
use of cn.beecloud.entity.BCQueryBillsResult in project ttdj by soonphe.
the class BCQueryTest method testQueryBillsAsyncSucc.
/**
* #3
* 正常response为200的情况
* @throws Exception
*/
@Test
public void testQueryBillsAsyncSucc() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
// please note this content is fake, there should be more content for bills, here just keep one record for the limit of space
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"bills\":[{\"spay_result\":false,\"create_time\":1447658025661,\"total_fee\":1,\"channel\":\"UN\",\"trade_no\":\"\",\"bill_no\":\"bc1447657931\",\"optional\":\"{\\\"test\\\":\\\"willreturn\\\"}\",\"revert_result\":false,\"title\":\"你的订单标题\",\"sub_channel\":\"UN_WEB\",\"refund_result\":false}]}";
// mock
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
query.queryBillsAsync(BCReqParams.BCChannelTypes.ALL, null, null, null, 2, 10, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCQueryBillsResult);
BCQueryBillsResult billsResult = (BCQueryBillsResult) result;
Assert.assertEquals((Integer) 0, billsResult.getResultCode());
// 最多可以获取到limit条数据
Assert.assertTrue(billsResult.getCount() == billsResult.getBills().size());
BCBillOrder billOrder = billsResult.getBills().get(0);
Assert.assertEquals("bc1447657931", billOrder.getBillNum());
Assert.assertEquals("你的订单标题", billOrder.getTitle());
Assert.assertEquals((Integer) 1, billOrder.getTotalFee());
Assert.assertEquals("UN", billOrder.getChannel());
Assert.assertEquals("UN_WEB", billOrder.getSubChannel());
Assert.assertFalse(billOrder.getPayResult());
Assert.assertFalse(billOrder.getRevertResult());
Assert.assertEquals((Long) 1447658025661L, billOrder.getCreatedTime());
Assert.assertEquals("{\"test\":\"willreturn\"}", billOrder.getOptional());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations