BCQuery { public void queryBillByIDAsync(final String id, final BCCallback callback) { if (callback == null) { Log.w(TAG, "请初始化callback"); return; } BCCache.executorService.execute(new Runnable() { @Override public void run() { if (id == null) { callback.done(new BCQueryBillResult(BCRestfulCommonResult.APP_INNER_FAIL_NUM, BCRestfulCommonResult.APP_INNER_FAIL, "id NPE!")); return; } BCQueryReqParams bcQueryReqParams; try { bcQueryReqParams = new BCQueryReqParams(BCReqParams.BCChannelTypes.ALL); } catch (BCException e) { callback.done(new BCQueryBillResult(BCRestfulCommonResult.APP_INNER_FAIL_NUM, BCRestfulCommonResult.APP_INNER_FAIL, e.getMessage())); return; } String queryURL = BCHttpClientUtil.getBillQueryURL() + "/" + id + "?para="; BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(queryURL + bcQueryReqParams.transToEncodedJsonString()); if (response.code == 200 || (response.code >= 400 && response.code < 500)) { try { callback.done(BCQueryBillResult.transJsonToResultObject(response.content)); } catch (JsonSyntaxException ex) { callback.done(new BCQueryBillResult(BCRestfulCommonResult.APP_INNER_FAIL_NUM, BCRestfulCommonResult.APP_INNER_FAIL, "JsonSyntaxException or Network Error:" + response.code + " # " + response.content)); } } else { callback.done(new BCQueryBillResult(BCRestfulCommonResult.APP_INNER_FAIL_NUM, BCRestfulCommonResult.APP_INNER_FAIL, "Network Error:" + response.code + " # " + response.content)); } } }); } private  BCQuery(); synchronized static BCQuery getInstance(); void queryBillsAsync(final BCReqParams.BCChannelTypes channel, final String billNum,
                                final Long startTime, final Long endTime,
                                final Integer skip, final Integer limit, final BCCallback callback); void queryBillsAsync(final BCReqParams.BCChannelTypes channel, final BCCallback callback); void queryBillsAsync(final BCReqParams.BCChannelTypes channel, final String billNum, final BCCallback callback); void queryBillsAsync(final QueryParams queryParams, final BCCallback callback); void queryRefundsAsync(final BCReqParams.BCChannelTypes channel, final String billNum, final String refundNum,
                                final Long startTime, final Long endTime,
                                final Integer skip, final Integer limit, final BCCallback callback); void queryRefundsAsync(final BCReqParams.BCChannelTypes channel, final BCCallback callback); void queryRefundsAsync(final BCReqParams.BCChannelTypes channel, final String billNum,
                                  final String refundNum, final BCCallback callback); void queryRefundsAsync(final QueryParams queryParams, final BCCallback callback); void queryBillsCountAsync(final QueryParams queryParams, final BCCallback callback); void queryRefundsCountAsync(final QueryParams queryParams, final BCCallback callback); void queryRefundStatusAsync(final BCReqParams.BCChannelTypes channel, final String refundNum,
                                       final BCCallback callback); void queryBillByIDAsync(final String id, final BCCallback callback); void queryRefundByIDAsync(final String id, final BCCallback callback); void queryOfflineBillStatusAsync(final BCReqParams.BCChannelTypes channelType,
                                          final String billNum,
                                          final BCCallback callback); void subscriptionSupportedBanks(final BCCallback callback); void queryPlans(final BCPlanCriteria criteria, final BCCallback callback); void querySubscriptions(final BCSubscriptionCriteria criteria, final BCCallback callback);  }
@Test public void testQueryBillByIDAsyncParamInvalid() throws Exception { query.queryBillByIDAsync(null, new BCCallback() { @Override public void done(BCResult result) { Assert.assertTrue(result instanceof BCQueryBillResult); BCQueryBillResult billResult = (BCQueryBillResult) result; Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billResult.getResultCode()); latch.countDown(); } }); latch.await(2000, TimeUnit.MILLISECONDS); }
@Test public void testQueryBillByIDAsyncNetworkError() throws Exception { final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response(); response.code = 400; response.content = "wrong"; 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(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billResult.getResultCode()); latch.countDown(); } }); latch.await(2000, TimeUnit.MILLISECONDS); }
@Test public void testQueryBillByIDAsyncSucc() throws Exception { 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}"; 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()); latch.countDown(); } }); latch.await(2000, TimeUnit.MILLISECONDS); }
@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}"; 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); }