Search in sources :

Example 16 with User

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

the class UserManagementControllerTest method testSubmitAddAdminUserForm.

/**
 * Test of submitAddUserForm method, of class UserManagementController.
 */
@Test
public void testSubmitAddAdminUserForm() throws Exception {
    setUpMockRoleDataService();
    setUpMockUserDataService(true, false, false);
    setUpMockAuthenticationContext();
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
    createUserCommand.setSiteUrl("http://www.newSite.com/");
    createUserCommand.setEmail("newUser@test.com");
    createUserCommand.setPassword("P4sSw0rD");
    createUserCommand.setConfirmPassword("P4sSw0rD");
    createUserCommand.setAdmin(true);
    createUserCommand.setActivated(true);
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("newUser@test.com", model.asMap().get(ADDED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.entity.user.User) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with User

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

the class CreateContractFormValidator method checkUsers.

/**
 * @param createContractCommand
 * @param errors
 * @return
 */
private boolean checkUsers(CreateContractCommand createContractCommand, Errors errors) {
    Collection<User> userList = createContractCommand.getUserList();
    if (userList == null || userList.isEmpty()) {
        return false;
    }
    boolean hasAtLeastOneRealUser = false;
    for (User user : userList) {
        if (user != null) {
            hasAtLeastOneRealUser = true;
        }
    }
    return hasAtLeastOneRealUser;
}
Also used : User(org.asqatasun.entity.user.User)

Example 18 with User

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

the class AuditSetUpCommandFactory method getGroupOfPagesUrl.

/**
 * This methods prepares the String table passed to the jsp that handles the
 * URL filled-in by the user. Depending the status of the user
 * (authenticated or guest), the table is pre-populated.
 */
private List<String> getGroupOfPagesUrl(Contract contract, boolean isSiteAudit) {
    User user = contract.getUser();
    /* 
         * WARNING hard-coded exception for guest user 
         * @TODO : do it better
         */
    int nbOfPages = AuditSetUpCommand.DEFAULT_LIST_SIZE;
    List<String> groupOfPagesUrl = new LinkedList();
    if (user == null) {
        return null;
    } else if (user.getEmail1().equalsIgnoreCase("guest") || isSiteAudit) {
        nbOfPages = 1;
    }
    for (int i = 0; i < nbOfPages; i++) {
        groupOfPagesUrl.add("");
    }
    // When the form is displayed for an authenticated user, it is
    // pre-populated with the Url recorded with the contract.
    String url = contractDataService.getUrlFromContractOption(contract);
    if (!StringUtils.isEmpty(url)) {
        groupOfPagesUrl.set(0, url);
    }
    return groupOfPagesUrl;
}
Also used : User(org.asqatasun.entity.user.User)

Example 19 with User

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

the class UserFactory method create.

public User create(String email1, String password, String name, String firstName, String address, String phoneNumber, String webUrl1, String webUrl2, String identicaId, String twitterId, Role role, String email2) {
    User user = create();
    user.setEmail1(email1);
    user.setPassword(password);
    user.setName(name);
    user.setAddress(address);
    user.setFirstName(firstName);
    user.setTwitterId(twitterId);
    user.setIdenticaId(identicaId);
    user.setWebUrl1(webUrl1);
    user.setWebUrl2(webUrl2);
    user.setRole(role);
    user.setPhoneNumber(phoneNumber);
    user.setEmail1(email2);
    return user;
}
Also used : User(org.asqatasun.entity.user.User)

Example 20 with User

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

the class ContractDAOTest method testFindAllContractsByUser.

/**
 * Test of findAllContractsByUser method, of class ContractDAOImpl.
 */
@Test
public void testFindAllContractsByUser() {
    User user = userDAO.read(1L);
    assertEquals(2, contractDAO.findAllContractsByUser(user).size());
    user = userDAO.read(2L);
    assertEquals(0, contractDAO.findAllContractsByUser(user).size());
}
Also used : 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