---
title: "service 接口测试用例"
author: "e_e"
date: "2022-06-24T16:35:35Z"
tags: []
categories: ["编程语言"]
slug: "service"
draft: false
lastmod: "2022-06-24T16:35:35Z"
id: 2537471
url: "https://e-e.iteye.com/blog/2537471"
---

```
@SpringBootTest(classes = TelemarketCoreApplication.class)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
public class CouponsInfoServiceTest {

    @MockBean
RestTemplate restTemplate;
@Autowired
private CouponsInfoService couponsInfoService;

@Before
public void setUp() {
        MockitoAnnotations.initMocks(this);
}

    @Test
public void getCouponsInfoOk() {
        String result = "{\"code\":1,\"success\":true,\"msg\":\"操作成功\",\"data\":[{\"couponType\":\"XFQ\",\"startTime\":\"2022-02-14 00:00:00\",\"endTime\":\"2022-02-16 00:00:00\",\"couponStatus\":\"4\",\"couponStatusName\":\"已过期\",\"couponName\":\"优惠券\",\"couponAmount\":100,\"couponNo\":\"a328d7918a50c21b7a151c98bec0319f\",\"couponTitle\":\"1. 本券限借款时使用，使用后，于前四期还款时生效，优惠金额累计最高100元，最终优惠金额以还款页面显示为准；2. 单笔借款限使用一张优惠券，本券限发放之日起3日内有效，过期作废；3. 满足单笔借款≥10000元可使用；4. 本券限用户主动还款、自动还款使用，如用户发生提前结清、逾期还款等不可用；\",\"createdTime\":\"2022-02-14 18:21:14\"},{\"couponType\":\"XFQ\",\"startTime\":\"2022-03-10 00:00:00\",\"endTime\":\"2022-03-12 00:00:00\",\"couponStatus\":\"4\",\"couponStatusName\":\"已过期\",\"couponName\":\"还款专属优惠券\",\"couponAmount\":20,\"couponNo\":\"ee0a9b0ff437cec95d7e411e3f473d3f\",\"couponTitle\":\"1. 本券限首期还款使用，优惠金额累计最高20元，最终优惠金额以还款页面显示为准；2. 单笔借款限使用一张优惠券，本券限发放之日起3日内有效，过期作废；3. 满足单笔借款为2000元使用；4. 本券限用户主动还款、自动还款使用，如用户发生提前结清、逾期还款等情况不可用；\",\"createdTime\":\"2022-03-10 08:39:46\"},{\"couponType\":\"XFQ\",\"startTime\":\"2022-06-10 00:00:00\",\"endTime\":\"2022-06-12 00:00:00\",\"couponStatus\":\"4\",\"couponStatusName\":\"已过期\",\"couponName\":\"还款专属优惠券\",\"couponAmount\":20,\"couponNo\":\"f7ec64c21b42b33553f623deb1b6f5e4\",\"couponTitle\":\"1. 本券限首期还款使用，优惠金额累计最高20元，最终优惠金额以还款页面显示为准；2. 单笔借款限使用一张优惠券，本券限发放之日起3日内有效，过期作废；3. 满足单笔借款为2000元使用；4. 本券限用户主动还款、自动还款使用，如用户发生提前结清、逾期还款等情况不可用；\",\"createdTime\":\"2022-06-10 12:29:54\"},{\"couponType\":\"XFQ\",\"startTime\":\"2022-06-18 00:00:00\",\"endTime\":\"2022-06-20 00:00:00\",\"couponStatus\":\"4\",\"couponStatusName\":\"已过期\",\"couponName\":\"优惠券\",\"couponAmount\":20,\"couponNo\":\"cccc879debaad7bde548ea76c2ef9bf4\",\"couponTitle\":\"1. 本券限借款时使用，使用后于首期还款时自动抵扣待还担保费，优惠金额累计最高20元，最终优惠金额以还款页面显示为准；2. 单笔借款限使用一张优惠券，本券限发放之日起3日内有效，过期作废；3. 满足单笔借款≥2000元可使用；4. 本券限用户主动还款、自动还款使用，如发生提前结清、逾期等不可用；5.该活动由豆豆钱平台负责解释说明；\",\"createdTime\":\"2022-06-18 08:55:45\"},{\"couponType\":\"XFQ\",\"startTime\":\"2022-06-21 00:00:00\",\"endTime\":\"2022-06-23 00:00:00\",\"couponStatus\":\"1\",\"couponStatusName\":\"待使用\",\"couponName\":\"优惠券\",\"couponAmount\":20,\"couponNo\":\"a54061469a6cb0fefa809d2a36b04ae3\",\"couponTitle\":\"1. 本券限借款时使用，使用后于首期还款时自动抵扣待还担保费，优惠金额累计最高20元，最终优惠金额以还款页面显示为准；2. 单笔借款限使用一张优惠券，本券限发放之日起3日内有效，过期作废；3. 满足单笔借款≥2000元可使用；4. 本券限用户主动还款、自动还款使用，如发生提前结清、逾期等不可用；5.该活动由豆豆钱平台负责解释说明；\",\"createdTime\":\"2022-06-21 09:29:52\"}]}";
Mockito.when(restTemplate.postForEntity("https://test-vipservice.vcredit.com/vcp/vmc-query-service/benefits/userCoupon/list?registerId=", null, String.class)).thenReturn(ResponseEntity.ok(result));
couponsInfoService.getCouponsInfo("", 1, 10, "");
}

    @Test
public void getCouponsInfo503() {
        String result = "{\"timestamp\":\"2022-06-21T01:32:12.118+00:00\",\"path\":\"/vmc-query-service/benefits/userCoupon/list\",\"status\":503,\"error\":\"Service Unavailable\",\"message\":\"\",\"requestId\":\"680b154d-4998854\"}";
Mockito.when(restTemplate.postForEntity("https://test-vipservice.vcredit.com/vcp/vmc-query-service/benefits/userCoupon/list?registerId=", null, String.class)).thenReturn(ResponseEntity.ok(result));
couponsInfoService.getCouponsInfo("", 1, 10, "");
}


}
```