@ ExtendWith (SpringExtension.class) @WebFluxTest (controllers = EventsControllerTest.class) class EventsControllerTest { @MockBean UserRepo репо; @Autowired частный WebTestClient webClient;
@Test
void testAssignUserRoles() {
UserInfo user = new UserInfo();
user.setId(Long.valueOf(1));
user.setFirstname("Test");
user.setLastname("Test2");
user.setActiveuser(true);
user.setEmailid("tet@test.com");
user.setRolename("test");
user.setUserpassword("test");
Mockito.when(repo.save(user)).thenReturn(Mono.just(user));
webClient.post().uri("/assignRoles").contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(user)).exchange().expectStatus().isCreated();
Mockito.verify(repo, times(1)).save(user);
}
Контроллер @RestController publi c class EventsController { @Autowired UserInfoRepository userInfoRepository;
@PostMapping(value = "/saveRole")
public Mono<UserInfo> assignUserRoles(@RequestBody UserInfo userInfo) {
return userInfoRepository.save(userInfo).log();
}