Search in sources :

Example 1 with UsersServiceInterface

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);
}
Also used : UsersServiceInterface(easytests.core.services.UsersServiceInterface) UserModelInterface(easytests.core.models.UserModelInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with UsersServiceInterface

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);
}
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 3 with UsersServiceInterface

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);
}
Also used : UsersServiceInterface(easytests.core.services.UsersServiceInterface) UserModelInterface(easytests.core.models.UserModelInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UsersServiceInterface (easytests.core.services.UsersServiceInterface)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 SubjectModelInterface (easytests.core.models.SubjectModelInterface)2 UserModelInterface (easytests.core.models.UserModelInterface)2 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)2 ArrayList (java.util.ArrayList)2 InOrder (org.mockito.InOrder)2 UserModel (easytests.core.models.UserModel)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1