KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > test > forums > AdminTestCase


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

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

24 public class AdminTestCase
25    extends WebTestCase
26 {
27    
28    public static final int floodtime = 30;
29    
30    public AdminTestCase(String JavaDoc name) {
31       super(name);
32       getTestContext().setBaseUrl("http://localhost.localdomain:8080/portal");
33 // getTestContext().setUserAgent("Mozilla");
34
}
35    
36    protected void setUp() throws Exception JavaDoc
37    {
38        super.setUp();
39        // initialize your database connection here
40
IDatabaseConnection connection = Utils.getConnection();
41
42        // initialize your dataset here
43
IDataSet dataSet = Utils.getDataSet("resources/test/forums.xml");
44
45        try
46        {
47           Utils.resetAutoIncrement();
48           DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
49        }
50        finally
51        {
52            connection.close();
53        }
54    }
55    
56    public void loginUser() {
57       beginAt("/index.html");
58       clickLink("standardlogin");
59       setFormElement("j_username", "admin");
60       setFormElement("j_password", "admin");
61       submit();
62   }
63
64    public void testReadIndex()
65    {
66       loginUser();
67       beginAt("/index.html?_id=page.default.forums");
68       assertLinkPresent("adminPanel");
69       assertTextPresent("Dummy demo category");
70       assertTextPresent("First forum");
71       assertTextPresent("Second forum");
72    }
73
74    public void testReadForum()
75    {
76       loginUser();
77       clickLinkWithText("forums");
78       clickLinkWithText("First forum");
79       assertTextPresent("First forum");
80       assertTextPresent("Page <b>1</b>");
81       assertLinkPresent("newTopic");
82    }
83
84    public void testPostTopic()
85    {
86       loginUser();
87       clickLinkWithText("forums");
88       clickLinkWithText("First forum");
89       clickLink("newTopic");
90       setFormElement("subject", "test topic");
91       setFormElement("message", "my message");
92       
93       submit("post");
94       assertTextPresent("Your message has been entered successfully.");
95    }
96    
97    public void testReplyTopic()
98    {
99       loginUser();
100       clickLinkWithText("forums");
101       clickLinkWithText("First forum");
102       clickLink("newTopic");
103       setFormElement("subject", "test topic");
104       setFormElement("message", "my message");
105       submit("post");
106       clickLinkWithText("First forum");
107       clickLinkWithText("test topic");
108       clickLink("postReply");
109       assertFormElementEquals("subject" , "Re: test topic");
110       setFormElement("message", "my answer");
111       // For flood control
112
try
113       {
114          Thread.sleep(floodtime * 1000);
115       }
116       catch (InterruptedException JavaDoc e)
117       {
118          // TODO Auto-generated catch block
119
e.printStackTrace();
120       }
121       submit("post");
122       assertTextPresent("Your message has been entered successfully.");
123    }
124    
125    public void testFlood()
126    {
127       loginUser();
128       clickLinkWithText("forums");
129       clickLinkWithText("First forum");
130       clickLink("newTopic");
131       setFormElement("subject", "test topic");
132       setFormElement("message", "my message");
133       submit("post");
134       assertTextPresent("Your message has been entered successfully.");
135       clickLinkWithText("First forum");
136       clickLink("newTopic");
137       setFormElement("subject", "test topic");
138       setFormElement("message", "my message");
139       submit("post");
140       assertTextPresent("You cannot make another post so soon after your last; please try again in a short while");
141    }
142    
143    public void testAddCategory()
144    {
145       loginUser();
146       clickLinkWithText("forums");
147       clickLink("adminPanel");
148       setFormElement("categoryname", "newcategory");
149       submit("addcategory");
150       assertTextPresent("Forum and Category information updated successfully");
151       assertLinkPresentWithText("newcategory");
152    }
153
154    public void testAddForum()
155    {
156       loginUser();
157       clickLinkWithText("forums");
158       clickLink("adminPanel");
159       setFormElement("forumname_1", "newforum");
160       submit("addforum_1");
161       assertFormElementEquals("forumname", "newforum");
162       setFormElement("forumname", "mynewforum");
163       setFormElement("forumdesc", "forumdesc");
164       submit();
165       assertTextPresent("Forum and Category information updated successfully");
166       assertLinkPresentWithText("mynewforum");
167       assertTextPresent("forumdesc");
168       
169    }
170
171     public void testWatchForum()
172     {
173       loginUser();
174       clickLinkWithText("forums");
175       clickLinkWithText("Watched Forums");
176       setFormElement("forum_id", "1");
177       assertLinkNotPresentWithText("First forum");
178       submit();
179       assertLinkPresentWithText("First forum");
180     }
181 }
182
Popular Tags