Skip to content

Instantly share code, notes, and snippets.

@mehmetcemyucel
Last active April 4, 2021 09:22
Show Gist options
  • Save mehmetcemyucel/f27a5321efec9371fce5bf7e80b562a2 to your computer and use it in GitHub Desktop.
Save mehmetcemyucel/f27a5321efec9371fce5bf7e80b562a2 to your computer and use it in GitHub Desktop.
mcy-sb-rest-test
//ORT: 2.186 MS
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { McySbRestTestApplication.class })
@WebAppConfiguration
public class RestServiceWebContextTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mvc;
@Before
public void setup() throws Exception {
this.mvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void test() throws Exception {
String requestBodyJson = "{ \"requestValue1\":\"val1\", \"requestValue2\":\"2\" }";
MvcResult result = mvc
.perform(post("/post-service").content(requestBodyJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
MockHttpServletResponse response = result.getResponse();
String responseMessage = response.getContentAsString();
assertThat(responseMessage).isEqualTo("{\"responseValue1\":\"val1service\",\"responseValue2\":2}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment