Rev 25 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16 | soliveira | 1 | package org.menta.action; |
2 | |||
18 | robertwgil | 3 | import static org.mentawai.core.Action.ERROR; |
4 | import static org.mentawai.core.Action.SUCCESS; |
||
16 | soliveira | 5 | import junit.framework.Assert; |
6 | |||
7 | import org.junit.Test; |
||
8 | import org.menta.AbstractBaseTest; |
||
18 | robertwgil | 9 | import org.menta.exception.LoginException.Type; |
16 | soliveira | 10 | import org.menta.model.Group; |
11 | import org.menta.model.Language; |
||
12 | import org.menta.model.User; |
||
13 | import org.mentawai.core.MapInput; |
||
14 | |||
15 | public class LoginActionTest extends AbstractBaseTest { |
||
16 | |||
17 | @Override |
||
18 | public void before() throws Exception { |
||
19 | |||
20 | super.before(); |
||
21 | |||
22 | User u = new User(); |
||
23 | u.setUsername("testUser"); |
||
24 | u.setPassword("abc123"); |
||
25 | u.setEmail("testUser@test.com"); |
||
26 | u.setGroupId(Group.ADMIN.getCode()); |
||
27 | u.setLanguageId(Language.ENGLISH.getCode()); |
||
28 | |||
29 | userDAO.insertOrUpdate(u); |
||
30 | } |
||
31 | |||
32 | @Test |
||
33 | public void login() throws Exception { |
||
34 | |||
35 | LoginAction login = getAction(LoginAction.class); |
||
36 | |||
37 | MapInput input = (MapInput) login.getInput(); |
||
38 | |||
39 | String result, errorId; |
||
40 | |||
41 | // test wrong password... |
||
25 | soliveira | 42 | result = login.execute("testUser", "wrong_pass"); |
16 | soliveira | 43 | |
27 | soliveira | 44 | errorId = login.getError("password"); |
16 | soliveira | 45 | |
46 | Assert.assertEquals(ERROR, result); |
||
18 | robertwgil | 47 | Assert.assertEquals(Type.WRONG_PASSWORD.toString(), errorId); |
16 | soliveira | 48 | |
49 | // test success... |
||
25 | soliveira | 50 | result = login.execute("testUser", "abc123"); |
16 | soliveira | 51 | |
52 | Assert.assertEquals(SUCCESS, result); |
||
53 | } |
||
54 | |||
55 | } |