Last active
April 4, 2021 09:22
-
-
Save mehmetcemyucel/f27a5321efec9371fce5bf7e80b562a2 to your computer and use it in GitHub Desktop.
mcy-sb-rest-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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