PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/bootstrap/ConfirmInviteControllerTest.java

http://sigma-h.googlecode.com/
Java | 80 lines | 51 code | 25 blank | 4 comment | 0 complexity | b3310bbd97a7d0d66a146b36d5a89df3 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.bootstrap;
 7
 8import org.junit.Before;
 9import org.junit.Test;
10import org.sigmah.server.bootstrap.model.ConfirmInvitePageModel;
11import org.sigmah.server.bootstrap.model.InvalidInvitePageModel;
12
13import javax.servlet.ServletException;
14import java.io.IOException;
15
16import static org.junit.Assert.*;
17
18public class ConfirmInviteControllerTest extends ControllerTestCase {
19
20    @Before
21    public void setUp() {
22        controller = new ConfirmInviteController(injector, templateCfg);
23    }
24
25    public void fillOutForm() {
26        req.addParameter("key", NEW_USER_KEY);
27        req.addParameter("password", "mynewpassword123");
28        req.addParameter("locale", NEW_USER_CHOSEN_LOCALE);
29        req.addParameter("name", NEW_USER_NAME);
30    }
31
32    @Test
33    public void requestWithValidKeyShouldGetView() throws IOException, ServletException {
34
35        req.setQueryString(NEW_USER_KEY);
36
37        get();
38
39        assertTemplateUsed(ConfirmInvitePageModel.class);
40        assertEquals(NEW_USER_KEY, lastNewUserPageModel().getUser().getChangePasswordKey());
41    }
42
43    @Test
44    public void badKeyShouldGetProblemPage() throws IOException, ServletException {
45
46        req.setQueryString(BAD_KEY);
47
48        get();
49
50        assertTemplateUsed(InvalidInvitePageModel.class);
51    }
52
53    @Test
54    public void passwordShouldBeSetAfterNewUserCompletion() throws IOException, ServletException {
55
56        fillOutForm();
57
58        post();
59
60        assertNotNull("password set", newUser.getHashedPassword());
61        assertEquals("name set", NEW_USER_NAME, newUser.getName());
62        assertEquals("locale set", NEW_USER_CHOSEN_LOCALE, newUser.getLocale());
63
64        assertNull("change password key cleared", newUser.getChangePasswordKey());
65        assertFalse("new user flag cleared", newUser.isNewUser());
66    }
67
68    @Test
69    public void emptyPasswordShouldNotBeAccepted() throws IOException, ServletException {
70
71        fillOutForm();
72        req.setParameter("password", "");
73
74        post();
75
76        assertTemplateUsed(ConfirmInvitePageModel.class);
77        assertTrue("error message set", lastNewUserPageModel().isFormIncomplete());
78    }
79
80}