use of easytests.core.services.UsersServiceInterface in project easy-tests by malinink.
the class UsersOptionsTest method testSaveWithRelations.
@Test
public void testSaveWithRelations() throws Exception {
final UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
final UsersOptionsInterface usersOptions = new UsersOptions();
final UsersServiceInterface usersService = Mockito.mock(UsersServiceInterface.class);
final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
usersOptions.setUsersService(usersService);
usersOptions.setSubjectsService(subjectsService);
usersOptions.withSubjects(subjectsOptions);
final List<SubjectModelInterface> subjectsModels = new ArrayList<>();
subjectsModels.add(Mockito.mock(SubjectModelInterface.class));
given(userModel.getSubjects()).willReturn(subjectsModels);
final InOrder inOrder = Mockito.inOrder(subjectsService, usersService);
usersOptions.saveWithRelations(userModel);
inOrder.verify(usersService).save(userModel);
inOrder.verify(subjectsService).save(subjectsModels, subjectsOptions);
}
use of easytests.core.services.UsersServiceInterface 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);
}
use of easytests.core.services.UsersServiceInterface in project easy-tests by malinink.
the class UsersOptionsTest method testDeleteWithRelations.
@Test
public void testDeleteWithRelations() throws Exception {
final UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
final UsersOptionsInterface usersOptions = new UsersOptions();
final UsersServiceInterface usersService = Mockito.mock(UsersServiceInterface.class);
final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
usersOptions.setUsersService(usersService);
usersOptions.setSubjectsService(subjectsService);
usersOptions.withSubjects(subjectsOptions);
final List<SubjectModelInterface> subjectsModels = new ArrayList<>();
subjectsModels.add(Mockito.mock(SubjectModelInterface.class));
given(userModel.getSubjects()).willReturn(subjectsModels);
final InOrder inOrder = Mockito.inOrder(subjectsService, usersService);
usersOptions.deleteWithRelations(userModel);
inOrder.verify(subjectsService).delete(subjectsModels, subjectsOptions);
inOrder.verify(usersService).delete(userModel);
}
Aggregations