Search in sources :

Example 1 with UserModel

use of easytests.core.models.UserModel in project easy-tests by malinink.

the class AuthUsersServiceTest method testLoadUserByUsername.

@Test
public void testLoadUserByUsername() throws Exception {
    final UsersServiceInterface usersService = Mockito.mock(UsersServiceInterface.class);
    final String email = "email3@gmail.com";
    userModel = new UserModel();
    userModel.setId(1);
    userModel.setFirstName("FirstName3");
    userModel.setLastName("LastName3");
    userModel.setSurname("Surname3");
    userModel.setEmail(email);
    userModel.setPassword("hash3");
    userModel.setIsAdmin(true);
    userModel.setState(3);
    when(usersService.findByEmail(email)).thenReturn(userModel);
    final UserDetails user = this.authUsersService.loadUserByUsername(email);
    Assert.assertEquals(usersService.findByEmail(email).getEmail(), user.getUsername());
    Assert.assertEquals(usersService.findByEmail(email).getPassword(), user.getPassword());
    Assert.assertEquals(usersService.findByEmail(email).getState() == 3, user.isEnabled());
    Assert.assertEquals(3, user.getAuthorities().size());
    verify(usersService, times(3)).findByEmail(email);
}
Also used : UserModel(easytests.core.models.UserModel) UsersServiceInterface(easytests.core.services.UsersServiceInterface) UserDetails(org.springframework.security.core.userdetails.UserDetails) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with UserModel

use of easytests.core.models.UserModel in project easy-tests by malinink.

the class UsersService method map.

private UserModelInterface map(UserEntity userEntity) {
    if (userEntity == null) {
        return null;
    }
    final UserModelInterface userModel = new UserModel();
    userModel.map(userEntity);
    return userModel;
}
Also used : UserModel(easytests.core.models.UserModel) UserModelInterface(easytests.core.models.UserModelInterface)

Example 3 with UserModel

use of easytests.core.models.UserModel in project easy-tests by malinink.

the class UsersController method insert.

@PostMapping("create/")
public String insert(Model model, @Valid UserModelDto userModelDto, BindingResult bindingResult) {
    this.userModelDtoValidator.validate(userModelDto, bindingResult);
    if (bindingResult.hasErrors()) {
        model.addAttribute("user", userModelDto);
        model.addAttribute("errors", bindingResult);
        setCreateBehaviour(model);
        return "admin/users/form";
    }
    final UserModelInterface userModel = new UserModel();
    userModelDto.mapInto(userModel);
    this.usersService.save(userModel);
    return "redirect:/admin/users/";
}
Also used : UserModel(easytests.core.models.UserModel) UserModelInterface(easytests.core.models.UserModelInterface)

Example 4 with UserModel

use of easytests.core.models.UserModel in project easy-tests by malinink.

the class UsersServiceTest method mapUserModel.

private UserModelInterface mapUserModel(UserEntity userEntity) {
    final UserModelInterface userModel = new UserModel();
    userModel.map(userEntity);
    return userModel;
}
Also used : UserModel(easytests.core.models.UserModel) UserModelInterface(easytests.core.models.UserModelInterface)

Aggregations

UserModel (easytests.core.models.UserModel)4 UserModelInterface (easytests.core.models.UserModelInterface)3 UsersServiceInterface (easytests.core.services.UsersServiceInterface)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1