View Javadoc

1   /*
2    * $Source: /usr/cvsroot/melati/melati/src/test/java/org/melati/test/test/PoemServletTestTest.java,v $
3    * $Revision: 1.9 $
4    *
5    * Copyright (C) 2008 Tim Pizey
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     Tim Pizey <timp At paneris.org>
42   *     http://paneris.org/~timp
43   */
44  package org.melati.test.test;
45  
46  import org.melati.JettyWebTestCase;
47  
48  import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
49  
50  
51  /**
52   * @author timp
53   * @since 6 Mar 2008
54   *
55   */
56  public class PoemServletTestTest extends JettyWebTestCase {
57  
58    protected String servletName;
59    
60    /**
61     * @param name
62     */
63    public PoemServletTestTest(String name) {
64      super(name);
65      servletName = "org.melati.test.PoemServletTest";
66    }
67  
68    /** 
69     * {@inheritDoc}
70     * @see junit.framework.TestCase#setUp()
71     */
72    protected void setUp() throws Exception {
73      super.setUp();
74    }
75  
76    /** 
77     * {@inheritDoc}
78     * @see junit.framework.TestCase#tearDown()
79     */
80    protected void tearDown() throws Exception {
81      super.tearDown();
82    }
83  
84    /**
85     * Click Exception link.
86     */
87    public void testException() {
88      setScriptingEnabled(false);
89      beginAt("/" + servletName + "/melatitest");
90      try { 
91        clickLinkWithText("Exception");
92      } catch (FailingHttpStatusCodeException e) { 
93        assertEquals(500, e.getStatusCode());
94      }
95      
96      assertTextPresent("MelatiBugMelatiException");
97    }
98    /**
99     * Click Exception link.
100    */
101   public void testAccessException() {
102     setScriptingEnabled(false);
103     beginAt("/" + servletName + "/melatitest" );
104     clickLinkWithText("Access Poem Exception");
105     assertTextPresent("You need the capability _administer_ ");
106     setTextField("field_login", "_administrator_");
107     setTextField("field_password", "FIXME");
108     checkCheckbox("rememberme");
109     submit("action");
110     assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
111   }
112   
113   /**
114    * Click Exception link.
115    */
116   public void testAccessAllowed() {
117     setScriptingEnabled(false);
118     beginAt("/org.melati.login.Login/admintest");
119     setTextField("field_login", "_administrator_");
120     setTextField("field_password", "FIXME");
121     checkCheckbox("rememberme");
122     submit("action");
123     gotoPage("/" + servletName + "/admintest");
124     clickLinkWithText("Access Poem Exception");
125     assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
126   }
127 
128   /**
129    * Click view.
130    */
131   public void testView() { 
132     setScriptingEnabled(false);
133     beginAt("/" + servletName +"/melatitest/");
134     clickLinkWithText("tableinfo/0/View");
135     assertTextPresent("logicalDatabase = melatitest, table = tableinfo, troid = 0, method = View");
136   }
137   /**
138    * Fill and click upload.
139    */
140   public void testUpload() { 
141     setScriptingEnabled(false);
142     beginAt("/org.melati.login.Login/admintest");
143     setTextField("field_login", "_administrator_");
144     setTextField("field_password", "FIXME");
145     checkCheckbox("rememberme");
146     submit("action");
147     gotoPage("/" + servletName + "/admintest/");
148 
149     setTextField("file","/dist/melati/melati/src/main/java/org/melati/admin/static/file.gif");
150     submit();
151     assertWindowPresent("Upload");
152     setTextField("file","/dist/melati/LICENSE-GPL.txt");
153     submit();
154     gotoWindow("Upload");
155     assertTextPresent("GNU GENERAL PUBLIC LICENSE");
156     
157   }
158   /**
159    * Fill and click upload.
160    */
161   public void testUploadNothing() { 
162     setScriptingEnabled(false);
163     beginAt("/org.melati.login.Login/admintest");
164     setTextField("field_login", "_administrator_");
165     setTextField("field_password", "FIXME");
166     checkCheckbox("rememberme");
167     submit("action");
168     gotoPage("/" + servletName + "/admintest/");
169 
170     //setTextField("file","/dist/melati/melati/src/main/java/org/melati/admin/static/file.gif");
171     submit();
172     gotoWindow("Upload");
173     assertTextPresent("No file was uploaded");
174     
175   }
176 
177 }