KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sourceforge.jwebunit.WebTestCase;
12
13 import org.dbunit.Assertion;
14 import org.dbunit.DatabaseUnitException;
15 import org.dbunit.database.IDatabaseConnection;
16 import org.dbunit.dataset.IDataSet;
17 import org.dbunit.operation.DatabaseOperation;
18 import org.jboss.portal.test.core.Utils;
19
20 /**
21  * @author <a HREF="theute@jboss.org">Thomas Heute </a>
22  * $Revision: 1.1 $
23  */

24 public class RolePortletTestCase extends WebTestCase {
25
26    protected void setUp() throws Exception JavaDoc
27    {
28        super.setUp();
29        // initialize your database connection here
30
IDatabaseConnection connection = Utils.getConnection();
31
32        // initialize your dataset here
33
IDataSet dataSet = Utils.getDataSet("resources/test/datarole.xml");
34
35        try
36        {
37           Utils.resetAutoIncrement();
38           DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
39           
40        }
41        finally
42        {
43            connection.close();
44        }
45    }
46
47     public RolePortletTestCase(String JavaDoc name) {
48         super(name);
49         getTestContext().setBaseUrl("http://localhost.localdomain:8080/portal");
50 // getTestContext().setUserAgent("Mozilla");
51
}
52     
53     public void loginAdmin() {
54         beginAt("/index.html?_id=page.default.admin");
55         clickLink("standardlogin");
56         setFormElement("j_username", "admin");
57         setFormElement("j_password", "admin");
58         submit();
59     }
60     
61     public void testPresence()
62     {
63         loginAdmin();
64         assertLinkPresent("createRole");
65         assertLinkPresent("editRole");
66     }
67
68     public void testCreateRole()
69     {
70         loginAdmin();
71         clickLink("createRole");
72         assertFormPresent("createRole");
73         assertFormElementPresent("rolename");
74         assertFormElementPresent("roledisplayname");
75         setFormElement("rolename", "myRole");
76         setFormElement("roledisplayname", "myDisplayRole");
77         submit();
78         assertLinkPresent("createRole");
79         assertLinkPresent("editRole");
80
81         try
82       {
83          Assertion.assertEquals(Utils.getDataSet("resources/test/datarolecreated.xml").getTable("jbp_roles"), Utils.getConnection().createDataSet().getTable("jbp_roles"));
84       }
85       catch (DatabaseUnitException e)
86       {
87          // TODO Auto-generated catch block
88
e.printStackTrace();
89       }
90       catch (Exception JavaDoc e)
91       {
92          // TODO Auto-generated catch block
93
e.printStackTrace();
94       }
95     }
96
97     public void testEditRole()
98     {
99         loginAdmin();
100         clickLink("editRole");
101         assertFormPresent("editRole");
102         assertFormElementPresent("roleid");
103         assertFormElementPresent("roledisplayname");
104         setWorkingForm("editRole");
105         setFormElement("roleid", "2");
106         setFormElement("roledisplayname", "myNewDisplayRole");
107         submit();
108         assertLinkPresent("createRole");
109         assertLinkPresent("editRole");
110         try
111         {
112            Assertion.assertEquals(Utils.getDataSet("resources/test/dataroleedited.xml").getTable("jbp_roles"), Utils.getConnection().createDataSet().getTable("jbp_roles"));
113         }
114         catch (DatabaseUnitException e)
115         {
116            // TODO Auto-generated catch block
117
e.printStackTrace();
118         }
119         catch (Exception JavaDoc e)
120         {
121            // TODO Auto-generated catch block
122
e.printStackTrace();
123         }
124     }
125
126     public void testDeleteRole()
127     {
128         loginAdmin();
129         clickLink("editRole");
130         assertFormPresent("deleteRole");
131         assertFormElementPresent("roleid");
132         setWorkingForm("deleteRole");
133         setFormElement("roleid", "2");
134         submit();
135         assertTextPresent("The role has been deleted");
136         try
137         {
138            Assertion.assertEquals(Utils.getDataSet("resources/test/dataroledeleted.xml").getTable("jbp_roles"), Utils.getConnection().createDataSet().getTable("jbp_roles"));
139         }
140         catch (DatabaseUnitException e)
141         {
142            // TODO Auto-generated catch block
143
e.printStackTrace();
144         }
145         catch (Exception JavaDoc e)
146         {
147            // TODO Auto-generated catch block
148
e.printStackTrace();
149         }
150     }
151 }
152
Popular Tags