Reputation: 694
Using Spring cloud contract to verify contract between my producer and consumer. In my consumer controller, I am using Feign client to call another micro-service method to get some data. But now in spring cloud contract making that stub call for this micro-service is impossible.
Using Spring Cloud with Netflix OSS.
Config-service and eureka is up. Now I installed my producer locally at port 8090. Consumer using Feign clients to call producer to get some data. Now I am getting 500 error. It is showing that URL not found. The closest match is /ping. I believe Feign client is unable to mock, it is somehow trying to connect with eureka not from the locally installed producer. Can you help me on it.
Any example or any idea will be great.
Thanks
Upvotes: 1
Views: 2807
Reputation: 1257
It is possible, here is my JUnit test that does it (ParticipantsService
uses a Feign Client)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureStubRunner(ids = {"com.ryanjbaxter.spring.cloud:ocr-participants:+:stubs"}, workOffline = true)
@DirtiesContext
@ActiveProfiles("test")
public class OcrRacesApplicationTestsBase {
@Autowired
protected ParticipantsService participantsService;
private List<Participant> participants = new ArrayList<>();
//Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
static {
System.setProperty("eureka.client.enabled", "false");
System.setProperty("spring.cloud.config.failFast", "false");
}
@Before
public void setup() {
this.participants = new ArrayList<>();
this.participants.add(new Participant("Ryan", "Baxter", "MA", "S", Arrays.asList("123", "456")));
this.participants.add(new Participant("Stephanie", "Baxter", "MA", "S", Arrays.asList("456")));
}
@After
public void tearDown() {
this.participants = new ArrayList<>();
}
@Test
public void contextLoads() {
List<Participant> participantList = participantsService.getAllParticipants();
assertEquals(participants, participantList);
}
}
Upvotes: 2