Package com.vst.model

Examples of com.vst.model.User


        request.addParameter("username", "tomcat");

        mv = c.handleRequest(request, new MockHttpServletResponse());

        assertEquals("userForm", mv.getViewName());
        User editUser = (User) mv.getModel().get(c.getCommandName());
        assertEquals("Tomcat User", editUser.getFullName());
    }
View Full Code Here


            throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'onSubmit' method...");
        }

        User user = (User) command;
        Locale locale = request.getLocale();

        Boolean encrypt = (Boolean) getConfiguration().get(Constants.ENCRYPT_PASSWORD);

        if (encrypt != null && encrypt.booleanValue()) {
            String algorithm = (String) getConfiguration().get(Constants.ENC_ALGORITHM);

            if (algorithm == null) { // should only happen for test case
                log.debug("assuming testcase, setting algorithm to 'SHA'");
                algorithm = "SHA";
            }

            user.setPassword(StringUtil.encodePassword(user.getPassword(), algorithm));
        }

        user.setEnabled(true);

        // Set the default user role on this new user
        user.addRole(roleManager.getRole(Constants.USER_ROLE));

        try {
            this.getUserManager().saveUser(user);
        } catch (UserExistsException e) {
            log.warn(e.getMessage());

            errors.rejectValue("username", "errors.existing.user",
                    new Object[]{
                            user.getUsername(), user.getEmail()
                    }, "duplicate user");

            // redisplay the unencrypted passwords
            user.setPassword(user.getConfirmPassword());
            return showForm(request, response, errors);
        }

        saveMessage(request, getText("user.registered", user.getUsername(), locale));
        request.getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);

        // log user in automatically
        Authentication auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword());
        try {
            ApplicationContext ctx =
                    WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
            if (ctx != null) {
                ProviderManager authenticationManager = (ProviderManager) ctx.getBean("authenticationManager");
                SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthentication(auth));
            }
        } catch (NoSuchBeanDefinitionException n) {
            // ignore, should only happen when testing
        }

        // Send user an e-mail
        if (log.isDebugEnabled()) {
            log.debug("Sending user '" + user.getUsername() + "' an account information e-mail");
        }

        // Send an account information e-mail
        message.setSubject(getText("signup.email.subject", locale));
        sendUserMessage(user, getText("signup.email.message", locale), RequestUtil.getAppURL(request));
View Full Code Here

            }
            if (hasFatalError) {
                request.setAttribute("errormessage", bundle.getString("commonMistake"));
            }
        }
        return new ModelAndView("userList", Constants.USER_LIST, mgr.getUsers(new User()));
    }
View Full Code Here

    /**
     * Simple test to verify BaseDao works.
     */
    public void testCRUD() {
        User user = new User();
        // set required fields
        user.setUsername("foo");

        // create
        // set expectations
        dao.expects(once()).method("saveObject").isVoid();

//        manager.saveObject(user);
//        dao.verify();

        // retrieve
        dao.reset();
        // expectations
        dao.expects(once()).method("getObject").will(returnValue(user));

//        user = (User) manager.getObject(User.class, user.getUsername());
//        dao.verify();

        // update
        dao.reset();
        dao.expects(once()).method("saveObject").isVoid();
        user.getAddress().setCountry(new GeoCountry("USA"));
//        manager.saveObject(user);
//        dao.verify();

        // delete
        dao.reset();
View Full Code Here

    /**
     * Simple test to verify BaseDao works.
     */
    public void testCRUD() {
        User user = new User();
        // set required fields
        user.setUsername("foo");
        user.setPassword("bar");
        user.setFirstName("first");
        user.setLastName("last");
        user.getAddress().setCity(new GeoCity("Denver"));
        user.getAddress().setPostalCode("80465");
        user.setEmail("foo@bar.com");

        // create
        dao.saveObject(user);
        assertNotNull(user.getId());

//        // retrieve
//        user = (User) dao.getObject(User.class, user.getId());
//        assertNotNull(user);
//        assertEquals(user.getLastName(), "last");
View Full Code Here

        roleDao = new Mock(RoleDao.class);
        roleManager.setRoleDao((RoleDao) roleDao.proxy());
    }
   
    public void testGetUser() throws Exception {
        User testData = new User("1");
        testData.getRoles().add(new Role("user"));
        // set expected behavior on dao
        userDao.expects(once()).method("getUser")
               .with(eq(new Long(1))).will(returnValue(testData));
       
        User user = userManager.getUser("1");
        assertTrue(user != null);
        assertTrue(user.getRoles().size() == 1);
        userDao.verify();
    }
View Full Code Here

        assertTrue(user.getRoles().size() == 1);
        userDao.verify();
    }

    public void testSaveUser() throws Exception {
        User testData = new User("1");
        testData.getRoles().add(new Role("user"));
        // set expected behavior on dao
        userDao.expects(once()).method("getUser")
               .with(eq(new Long(1))).will(returnValue(testData));
       
        User user = userManager.getUser("1");
        user.setPhoneNumber("303-555-1212");
        userDao.verify();
       
        // reset expectations
        userDao.reset();
        userDao.expects(once()).method("saveUser").with(same(user));
       
        userManager.saveUser(user);
        assertTrue(user.getPhoneNumber().equals("303-555-1212"));
        assertTrue(user.getRoles().size() == 1);
        userDao.verify();
    }
View Full Code Here

        assertTrue(user.getRoles().size() == 1);
        userDao.verify();
    }

    public void testAddAndRemoveUser() throws Exception {
        User user = new User();

        // call populate method in super class to populate test data
        // from a properties file matching this class name
        user = (User) populate(user);
       
        // set expected behavior on role dao
        roleDao.expects(once()).method("getRoleByName")
               .with(eq("user")).will(returnValue(new Role("user")));
       
        Role role = roleManager.getRole(Constants.USER_ROLE);
        roleDao.verify();
        user.addRole(role);

        // set expected behavior on user dao
        userDao.expects(once()).method("saveUser").with(same(user));
       
        userManager.saveUser(user);
        assertTrue(user.getUsername().equals("john"));
        assertTrue(user.getRoles().size() == 1);
        userDao.verify();
       
        // reset expectations
        userDao.reset();
       
View Full Code Here

        userDao.verify();
    }
   
    public void testUserExistsException() {
        // set expectations
        User user = new User("admin");
        user.setEmail("matt@raibledesigns.com");
        List users;
        users = new ArrayList();

        users.add(user);
        Exception ex = new DataIntegrityViolationException("");
View Full Code Here

   
    public void testAddUserWithoutAdminRole() throws Exception {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        assertTrue(auth.isAuthenticated());
        UserManager userManager = makeInterceptedTarget();
        User user = new User("admin");

        try {
            userManager.saveUser(user);
            fail("AccessDeniedException not thrown");
        } catch (AccessDeniedException expected) {
View Full Code Here

TOP

Related Classes of com.vst.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.