I'm trying to write an integration test with mockmvc, but I'm getting an error. While startDate and endDate, which I receive as request param, normally work without any problems, I get the following error in the test; MethodArgumentTypeMismatchException
My controller
@GetMapping("/")
public ResponseEntity<List<TransactionDto>> getTransactionByDateRange(@RequestParam LocalDate startDate,
@RequestParam LocalDate endDate) {
logger.info("Get transaction request received with date range, start date: {} and end date: {}",
startDate,
endDate);
List<TransactionDto> transactionDtoList = transactionService.findTransactionByDateRange(startDate,endDate);
if(transactionDtoList.isEmpty()){
throw new TransactionListIsEmptyException("No transaction data can be found in this date range. " +
"Please check the date range you entered.");
}
return new ResponseEntity(Response.ok().setPayload(transactionDtoList), HttpStatus.OK);
}
My Test
@Test
public void testfindTransactionByDateRange_whenTransactionsAreExists_ShouldReturnTransactionDtoList() throws Exception {
//given
LocalDate startDate = LocalDate.of(2020,10,5);
LocalDate endDate = LocalDate.now();
Transaction transaction = transactionRepository.save(generateTransaction());
Transaction transaction2 = transactionRepository.save(generateTransaction());
Transaction transaction3 = transactionRepository.save(generateTransaction());
transactionService.createTransaction(transaction);
transactionService.createTransaction(transaction2);
transactionService.createTransaction(transaction3);
List<Transaction> transactionList = new ArrayList<>();
transactionList.add(transaction);
transactionList.add(transaction2);
transactionList.add(transaction3);
List<TransactionDto> expected = converter.convertList(transactionList);
//when
//then
this.mockMvc.perform(get(TRANSACTION_API_ENDPOINT)
.queryParam("startDate","10.10.2015")
.queryParam("endDate","10.10.2015"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}