MockMvc PostRequest异常

时间:2018-11-08 19:53:58

标签: spring-boot junit mocking spring-boot-test mockmvc

我有以下帖子映射。

@PostMapping(value = BULK_UPDATE)
@ApiOperation(value = "Bulk Update of Markets by pairs of Market Key and Tier Quantity Id", tags = "Bulk", code = 200)
@ApiImplicitParams({
        @ApiImplicitParam(name = "MarketTierQuantityId", value = "List of Market Key and Tier Quantity Id pairs",
                paramType = "body", allowMultiple = true, dataType = "MarketTierQuantityId", required = true) })
@ApiResponses({
        @ApiResponse(code = 200, message = "Bulk update successful", response = MarketStatus.class, responseContainer = "List") })
@ResponseStatus(org.springframework.http.HttpStatus.OK)
public ResponseEntity<StreamingResponseBody> bulkUpdate(
        @RequestParam(name = IGNORE_SYNC_PAUSE_FAILURE, required = false, defaultValue = "false")
        @ApiParam(name = IGNORE_SYNC_PAUSE_FAILURE, value = "Ignore failure of the jobs pause command") boolean ignoreJobsPauseFailure,
        @RequestBody @ApiParam(name = "MarketTierQuantityId", value = "List of Market Key and Tier Quantity Id pairs", required = true) List<MarketTierQuantityId> marketTierQuantities,
        @RequestParam(name = MOVE_TO_PREAUTH_FLAG, required = false, defaultValue = "true")
        @ApiParam(name = MOVE_TO_PREAUTH_FLAG, value = "Move new units to Preauth for the markets with active waitlists") boolean moveToPreauth) throws BusinessException {
    String requestId = getRequestId();
    boolean jobsPaused = pauseJobs(ignoreJobsPauseFailure);

    return LoggingStopWatch.wrap(() -> {
        return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
                .body(outputStream -> process(new SyncBulkProcessorHelper(outputStream),
                        marketTierQuantities, jobsPaused, requestId, moveToPreauth, LoggingStopWatch.create(LOGGER, "Bulk Update")));
    });
}

我已经写了以下测试。

@RunWith(SpringRunner.class)
@WebMvcTest(BulkUpdateController.class)
@ContextConfiguration(classes = { BulkUpdateController.class, SharedExecutor.class })
@ActiveProfiles("dev")
public class BulkUpdateControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @MockBean
    private BulkStatusService bulkStatusService;

    @MockBean
    private BulkMarketService bulkMarketService;

    @MockBean
    private HttpService httpService;

    @MockBean
    private RestClient restClient;

    @MockBean
    private BulkProcessorHelper helper;


    @Test
    public void test() throws Exception {
        String request = TestHelper.getSerializedRequest(getBulkUpdateRequest(), MarketTierQuantityId.class);
        mockMvc.perform(post("/bulkupdate").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
                .content(request)).andExpect(status().is4xxClientError());
    }


    public MarketTierQuantityId getBulkUpdateRequest() {
        MarketTierQuantityId market = new MarketTierQuantityId();
        market.setMarketKey("00601|PR|COBROKE|POSTALCODE|FULL");
        market.setTierQuantityId("10");
        return market;
    }

遇到以下错误,尝试了所有可能的方法来解决它,但没有帮助。

  

请求失败。错误回应:   {\“ responseStatus \”:{\“ errorCode \”:\“ BadRequest \”,\“ message \”:\“ JSON   解析错误:无法反序列化java.util.ArrayList的实例   START_OBJECT令牌\“,\” stackTrace \“:\” BusinessException(JSON解析   错误:

PS-> JUnits和模拟的新功能

0 个答案:

没有答案
相关问题