I made some cucumber tests (given, when, then integration tests) in spring boot maven, and I was able to test my endpoints using TestRestTemplate, but only if the external service is running.
The external service job is to check some fields before I save the information to the database.
When running the application normally the external service is called by FeignClient.
Is it possible to mock the external service while using TestRestTemplate to test the endpoints?
EDIT:
Sample mockup of the structure
Controller.java
@Autowired
EmployeeSvc employeeSvc;
@PostMapping(/save)
public ResponseEntity<String> saveEmployee(@RequestBody EmployeeDTO employeeDTO) {
employeeSvc.save(employeeDTO);
}
EmployeeSvc.java
@Autowired
ExternalSvcClient externalSvcClient; //External service is called by feignclient here.
@Autowired
EmployeeRepository employeeRepository;
public void save(EmployeeDTO employeeDTO) {
externalSvcClient.check(employeeDTO);
...some other code
Employee employee = dtoTransformer.transoform(employeeDTO);
employeeRepository.save(employee);
}