Search in sources :

Example 1 with BCBillOrder

use of cn.beecloud.entity.BCBillOrder 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 2 with BCBillOrder

use of cn.beecloud.entity.BCBillOrder in project ttdj by soonphe.

the class BCQueryTest method testQueryBillByIDAsyncSucc.

/**
 * #3
 * 模拟response为200
 * @throws Exception
 */
@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}";
    // 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());
            // 释放
            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 3 with BCBillOrder

use of cn.beecloud.entity.BCBillOrder 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);
}
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 4 with BCBillOrder

use of cn.beecloud.entity.BCBillOrder 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);
}
Also used : BCQueryBillsResult(cn.beecloud.entity.BCQueryBillsResult) BCCallback(cn.beecloud.async.BCCallback) BCBillOrder(cn.beecloud.entity.BCBillOrder) SimpleDateFormat(java.text.SimpleDateFormat) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BCBillOrder

use of cn.beecloud.entity.BCBillOrder 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);
}
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)

Aggregations

BCCallback (cn.beecloud.async.BCCallback)7 BCResult (cn.beecloud.async.BCResult)7 BCBillOrder (cn.beecloud.entity.BCBillOrder)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 BCQueryBillsResult (cn.beecloud.entity.BCQueryBillsResult)5 BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)2 SimpleDateFormat (java.text.SimpleDateFormat)1