Search in sources :

Example 26 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method setUpMockUserDataService.

private void setUpMockUserDataService(boolean hasCreateCall, boolean hasUpdateUserCall, boolean hasUpdateAdminCall) {
    // initialise the context with the user identified by the email
    // "test1@test.com" seen as authenticated
    Collection<User> userCollection = new ArrayList<>();
    mockAdminUser = new User();
    mockUser = new User();
    mockNewUser = new User();
    when(mockUserDataService.findAll()).thenReturn(userCollection);
    when(mockUserDataService.read(4L)).thenReturn(mockAdminUser);
    when(mockUserDataService.getUserFromEmail("admin@test.com")).thenReturn(mockAdminUser);
    when(mockUserDataService.read(5L)).thenReturn(mockUser);
    when(mockUserDataService.getUserFromEmail("user@test.com")).thenReturn(mockUser);
    when(mockUserDataService.read(6L)).thenReturn(null);
    when(mockUserDataService.getUserFromEmail("null")).thenReturn(null);
    when(mockUserDataService.getUserFromEmail("newUser@test.com")).thenReturn(null);
    if (hasCreateCall) {
        when(mockUserDataService.create()).thenReturn(mockNewUser);
        mockNewUser.setEmail1("newUser@test.com");
        mockNewUser.setPassword("6eccfd91aa8a36582fbf64b8ea533692");
        mockNewUser.setWebUrl1("http://www.newSite.com/");
        mockNewUser.setPhoneNumber(null);
        mockNewUser.setName(null);
        mockNewUser.setFirstName(null);
        mockNewUser.setAccountActivation(false);
        mockNewUser.setRole(mockUserRole);
        when(mockUserDataService.saveOrUpdate(mockNewUser)).thenReturn(mockNewUser);
        mockNewUser.setEmail1("newUser@test.com");
    }
    if (hasUpdateUserCall) {
        mockUser.setEmail1("user@test.com");
        mockUser.setName("newName");
        mockUser.setFirstName("newFirstName");
        mockUser.setRole(mockAdminRole);
        mockUser.setAccountActivation(false);
        mockUser.setPhoneNumber("0102030405");
        when(mockUserDataService.saveOrUpdate(mockUser)).thenReturn(mockUser);
        mockUser.setEmail1("user@test.com");
    }
    mockAdminUser.setEmail1("admin@test.com");
    mockAdminUser.setWebUrl1("http://www.admin.com");
    mockAdminUser.setFirstName("firstNameAdmin");
    mockAdminUser.setName("nameAdmin");
    mockAdminUser.setPhoneNumber("0123456789");
    mockAdminUser.setAccountActivation(true);
    mockAdminUser.setId(4L);
    mockAdminUser.setRole(mockAdminRole);
    if (hasUpdateAdminCall) {
        mockAdminUser.setName("newName");
        mockAdminUser.setFirstName("newFirstName");
        mockAdminUser.setPhoneNumber("0102030405");
        when(mockUserDataService.saveOrUpdate(mockAdminUser)).thenReturn(mockAdminUser);
        mockAdminUser.setEmail1("admin@test.com");
    }
    mockUser.setEmail1("user@test.com");
    mockUser.setWebUrl1("http://www.user.com");
    mockUser.setFirstName("firstNameUser");
    mockUser.setName("nameUser");
    mockUser.setPhoneNumber("9876543210");
    mockUser.setAccountActivation(false);
    mockUser.setId(5L);
    mockUser.setRole(mockUserRole);
}
Also used : User(org.asqatasun.entity.user.User) ArrayList(java.util.ArrayList)

Example 27 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOTest method testRead.

@Test
public void testRead() {
    User user = userDAO.read(1L);
    assertEquals("Test1", user.getName());
    assertEquals("Role1", user.getRole().getRoleName());
    user = userDAO.read(2L);
    assertEquals("Test2", user.getName());
    assertEquals("Role2", user.getRole().getRoleName());
}
Also used : User(org.asqatasun.entity.user.User) Test(org.junit.Test)

Example 28 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOTest method testFindUserFromName.

@Test
public void testFindUserFromName() {
    User user = userDAO.findUserFromName("Test1");
    assertEquals(Long.valueOf(1), user.getId());
    user = userDAO.findUserFromName("test");
    assertNull(user);
}
Also used : User(org.asqatasun.entity.user.User) Test(org.junit.Test)

Example 29 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOTest method testFindUserFromEmail.

@Test
public void testFindUserFromEmail() {
    User user = userDAO.findUserFromEmail("test1@test.com");
    assertEquals(Long.valueOf(1), user.getId());
    assertEquals(2, user.getContractSet().size());
    user = userDAO.findUserFromEmail("test@test.com");
    assertNull(user);
}
Also used : User(org.asqatasun.entity.user.User) Test(org.junit.Test)

Example 30 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class OptionImplElementDAOTest method testFindOptionElementFromUserAndFamilyCode.

/**
 * Test of findOptionElementFromUserAndFamilyCode method, of class OptionElementDAOImpl.
 */
@Test
public void testFindOptionElementFromUserAndFamilyCode() {
    User user1 = userDAO.findUserFromEmail("test1@test.com");
    User user2 = userDAO.findUserFromEmail("test2@test.com");
    User user3 = userDAO.findUserFromEmail("test3@test.com");
    Collection<OptionElementImpl> oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "USER_OPTION");
    assertEquals(2, oec.size());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "USER_OPTION");
    assertEquals(1, oec.size());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "USER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) User(org.asqatasun.entity.user.User) Test(org.junit.Test)

Aggregations

User (org.asqatasun.entity.user.User)40 Secured (org.springframework.security.access.annotation.Secured)14 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Contract (org.asqatasun.entity.contract.Contract)5 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)5 Test (org.junit.Test)5 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)4 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)4 Model (org.springframework.ui.Model)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 BindingResult (org.springframework.validation.BindingResult)4 List (java.util.List)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ArrayList (java.util.ArrayList)1 OptionElement (org.asqatasun.entity.option.OptionElement)1