KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > core > portlet > UserPortletTestCase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.core.portlet;
10
11 import org.dbunit.database.IDatabaseConnection;
12 import org.dbunit.dataset.IDataSet;
13 import org.dbunit.operation.DatabaseOperation;
14 import org.jboss.portal.test.core.Utils;
15
16 import net.sourceforge.jwebunit.WebTestCase;
17
18 /**
19  * @author <a HREF="theute@jboss.org">Thomas Heute </a>
20  * $Revision: 1.2 $
21  */

22 public class UserPortletTestCase extends WebTestCase {
23
24     public UserPortletTestCase(String JavaDoc name) {
25         super(name);
26         getTestContext().setBaseUrl("http://localhost.localdomain:8080/portal");
27 // getTestContext().setUserAgent("Mozilla");
28
}
29     
30     protected void setUp() throws Exception JavaDoc
31     {
32         super.setUp();
33         // initialize your database connection here
34
IDatabaseConnection connection = Utils.getConnection();
35
36         // initialize your dataset here
37
IDataSet dataSet = Utils.getDataSet("resources/test/datarole.xml");
38
39         try
40         {
41            Utils.resetAutoIncrement();
42            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
43            
44         }
45         finally
46         {
47             connection.close();
48         }
49     }
50     
51     public void testPresence() {
52         beginAt("/index.html");
53         assertLinkPresent("standardlogin");
54         assertLinkPresent("register");
55     }
56
57     public void testClickRegister() {
58         beginAt("/index.html");
59         clickLink("register");
60         assertFormPresent("register");
61         assertFormElementPresent("uname");
62         assertFormElementPresent("pass1");
63         assertFormElementPresent("pass2");
64         assertFormElementPresent("realemail");
65         assertFormElementPresent("fakeemail");
66         assertFormElementPresent("question");
67         assertFormElementPresent("answer");
68         assertSubmitButtonPresent("register");
69         assertLinkPresent("login");
70     }
71
72     public void testClickLogin() {
73        beginAt("/index.html");
74        clickLink("standardlogin");
75        assertFormPresent("loginform");
76        assertFormElementPresent("j_username");
77        assertFormElementPresent("j_password");
78        assertSubmitButtonPresent("login");
79    }
80
81     
82     public void testRegister() {
83         beginAt("/index.html");
84         clickLink("register");
85         setFormElement("uname", "testingDude");
86         setFormElement("pass1", "testingPassword");
87         setFormElement("pass2", "testingPassword");
88         setFormElement("realemail", "email@exemple.com");
89         submit();
90     }
91     
92     public void testUserLogin() {
93         beginAt("/index.html");
94         clickLink("standardlogin");
95         setFormElement("j_username", "user");
96         setFormElement("j_password", "user");
97         submit();
98         assertLinkPresent("editprofile");
99         assertLinkNotPresent("listusers");
100         assertLinkPresent("logout");
101     }
102     
103     public void testAdminLogin() {
104        beginAt("/index.html");
105        clickLink("standardlogin");
106        setFormElement("j_username", "admin");
107        setFormElement("j_password", "admin");
108        submit();
109        assertLinkPresent("editprofile");
110        assertLinkPresent("listusers");
111        assertLinkPresent("logout");
112    }
113
114     public void testLogout()
115     {
116        beginAt("/index.html");
117        clickLink("standardlogin");
118        setFormElement("j_username", "user");
119        setFormElement("j_password", "user");
120        submit();
121        clickLink("logout");
122        assertLinkPresent("standardlogin");
123     }
124 }
125
Popular Tags