I am using FeignClient for communication between microservices. I would like to test one microservice without running the other, so I need somehow to emulate responses from it. At this time I am mocking feignClient. However is it a right way for emulating FeignClient's responses in this situation?
My FeignClient:
@FeignClient(name="shortestPath", url="http://localhost:5000")
public interface GraphFeignClient {
@PostMapping(path="/short")
public List<Integer> getShortestPath(@RequestParam("source") int source,
@RequestParam("target") int target,
@RequestBody Graph graph);
}
My test:
@SpringBootTest
public class GraphJsonApplicationTests {
@Mock
GraphFeignClient graphFeignClient;
@Autowired
@InjectMocks
private GraphServiceClient graphServiceClient;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testSavingShortestPath() throws Exception {
given(graphFeignClient.getShortestPath(anyInt(),anyInt(),any()))
.willReturn(Arrays.asList(1,2,3,4,5));
//...
}
}