KickJava   Java API By Example, From Geeks To Geeks.

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


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 UserTestCase
25    extends WebTestCase
26 {
27    public UserTestCase(String JavaDoc name) {
28       super(name);
29       getTestContext().setBaseUrl("http://localhost.localdomain:8080/portal");
30 // getTestContext().setUserAgent("Mozilla");
31
}
32    
33    protected void setUp() throws Exception JavaDoc
34    {
35        super.setUp();
36        // initialize your database connection here
37
IDatabaseConnection connection = Utils.getConnection();
38
39        // initialize your dataset here
40
IDataSet dataSet = Utils.getDataSet("resources/test/forums.xml");
41
42        try
43        {
44           Utils.resetAutoIncrement();
45           DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
46        }
47        finally
48        {
49            connection.close();
50        }
51    }
52
53    
54    public void loginUser() {
55       beginAt("/index.html");
56       clickLink("standardlogin");
57       setFormElement("j_username", "user");
58       setFormElement("j_password", "user");
59       submit();
60   }
61
62    public void testReadIndex()
63    {
64       loginUser();
65       clickLinkWithText("forums");
66       assertTextPresent("Dummy demo category");
67       assertTextPresent("First forum");
68       assertTextPresent("Second forum");
69    }
70
71    public void testReadForum()
72    {
73       loginUser();
74       clickLinkWithText("forums");
75       clickLinkWithText("First forum");
76       assertTextPresent("First forum");
77       assertTextPresent("Page <b>1</b>");
78       assertLinkPresent("newTopic");
79    }
80
81    public void testPostTopic()
82    {
83       loginUser();
84       clickLinkWithText("forums");
85       clickLinkWithText("First forum");
86       clickLink("newTopic");
87       setFormElement("subject", "test topic");
88       setFormElement("message", "my message");
89       submit("post");
90       assertTextPresent("Your message has been entered successfully.");
91    }
92    
93    public void testReplyTopic()
94    {
95       loginUser();
96       clickLinkWithText("forums");
97       clickLinkWithText("First forum");
98       clickLink("newTopic");
99       setFormElement("subject", "test topic");
100       setFormElement("message", "my message");
101       submit("post");
102       clickLinkWithText("First forum");
103       clickLinkWithText("test topic");
104       clickLink("postReply");
105       assertFormElementEquals("subject" , "Re: test topic");
106       setFormElement("message", "my answer");
107       // For flood control
108
try
109       {
110          Thread.sleep(30*1000);
111       }
112       catch (InterruptedException JavaDoc e)
113       {
114          // TODO Auto-generated catch block
115
e.printStackTrace();
116       }
117       submit("post");
118       assertTextPresent("Your message has been entered successfully.");
119    }
120    
121
122 }
123
Popular Tags