Last active
April 4, 2021 09:23
-
-
Save mehmetcemyucel/4cd1ddd05562b916e0c38ceed1eb6dbd 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: 556 MS | |
public class RestServiceStandaloneTest { | |
@InjectMocks | |
private RestService restService; | |
@Mock | |
private SecondService service; | |
private MockMvc mvc; | |
@Before | |
public void setup() { | |
MockitoAnnotations.initMocks(this); | |
when(service.getValue()).thenReturn("service"); | |
mvc = MockMvcBuilders.standaloneSetup(restService).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