Gurinder spring cloud contract (#3547)
* adding producer side sample for spring-cloud-contract * adding consumer side sample for spring-cloud-contract * removing un neccessary code * adding latest version for spring-cloud-contract in both producer and consumer * adding producer dependency in consumer * refactoring after review-1 * refactoring after review-2 * refactoring after review-3
This commit is contained in:
committed by
KevinGilmore
parent
414d805f6b
commit
b219245e5b
+44
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.spring.cloud.springcloudcontractconsumer.controller;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
@AutoConfigureMockMvc
|
||||
@AutoConfigureJsonTesters
|
||||
@AutoConfigureStubRunner(workOffline = true,
|
||||
ids = "com.baeldung.spring.cloud:spring-cloud-contract-producer:+:stubs:8090")
|
||||
public class BasicMathControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
public void given_WhenPassEvenNumberInQueryParam_ThenReturnEven() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/calculate?number=2")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("Even"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void given_WhenPassOddNumberInQueryParam_ThenReturnOdd() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/calculate?number=1")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("Odd"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user