Skip to content

Instantly share code, notes, and snippets.

@mehmetcemyucel
Last active April 4, 2021 09:23
Show Gist options
  • Save mehmetcemyucel/4cd1ddd05562b916e0c38ceed1eb6dbd to your computer and use it in GitHub Desktop.
Save mehmetcemyucel/4cd1ddd05562b916e0c38ceed1eb6dbd to your computer and use it in GitHub Desktop.
mcy-sb-rest-test
// 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