@SpringBootTest(webEnvironment = RANDOM_PORT)
@ContextConfiguration(classes = {PresApplication.class})
@WithUserDetails(value = "demo_user", userDetailsServiceBeanName = "customDbUserDetailsService")
@AutoConfigureMockMvc
@ActiveProfiles(value = "local")
class PersonControllerTest
{
@Autowired
private MockMvc mockMvc;
@MockBean
private PersonService personService;
@Test
void getPersonById() throws Exception
{
var personId = 1L;
when(personService.findPersonById(personId)).thenReturn(new Person());
this.mockMvc.perform(get("/api/v1/person/find/" + personId)).andDo(print()).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
}
Last active
December 22, 2021 23:28
-
-
Save pavankjadda/41e05529f76a07cf8c7f749e2c8335ff to your computer and use it in GitHub Desktop.
Spring Boot Controller layer unit Test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment