View Javadoc
1   /*
2    * $Source$
3    * $Revision$
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 java.io.File;
47  
48  import org.melati.JettyWebTestCase;
49  
50  import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
51  
52  
53  /**
54   * @author timp
55   * @since 6 Mar 2008
56   *
57   */
58  public class PoemServletTestTest extends JettyWebTestCase {
59  
60    protected String servletName;
61    
62    /**
63     * @param name
64     */
65    public PoemServletTestTest(String name) {
66      super(name);
67      servletName = "org.melati.test.PoemServletTest";
68    }
69  
70    /** 
71     * {@inheritDoc}
72     * @see junit.framework.TestCase#setUp()
73     */
74    protected void setUp() throws Exception {
75      super.setUp();
76    }
77  
78    /** 
79     * {@inheritDoc}
80     * @see junit.framework.TestCase#tearDown()
81     */
82    protected void tearDown() throws Exception {
83      super.tearDown();
84    }
85  
86    /**
87     * Click Exception link.
88     */
89    public void testException() {
90      setScriptingEnabled(false);
91      beginAt("/" + servletName + "/melatitest");
92      try { 
93        clickLinkWithText("Exception");
94      } catch (FailingHttpStatusCodeException e) { 
95        assertEquals(500, e.getStatusCode());
96      }
97      
98      assertTextPresent("MelatiBugMelatiException");
99    }
100   /**
101    * Click Exception link.
102    */
103   public void testAccessException() {
104     setScriptingEnabled(false);
105     beginAt("/" + servletName + "/melatitest" );
106     clickLinkWithText("Access Poem Exception");
107     assertTextPresent("You need the capability _administer_ ");
108     setTextField("field_login", "_administrator_");
109     setTextField("field_password", "FIXME");
110     checkCheckbox("rememberme");
111     submit("action");
112     assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
113   }
114   
115   /**
116    * Click Exception link.
117    */
118   public void testAccessAllowed() {
119     setScriptingEnabled(false);
120     beginAt("/org.melati.login.Login/admintest");
121     setTextField("field_login", "_administrator_");
122     setTextField("field_password", "FIXME");
123     checkCheckbox("rememberme");
124     submit("action");
125     gotoPage("/" + servletName + "/admintest");
126     clickLinkWithText("Access Poem Exception");
127     assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
128   }
129 
130   /**
131    * Click view.
132    */
133   public void testView() { 
134     setScriptingEnabled(false);
135     beginAt("/" + servletName +"/melatitest/");
136     clickLinkWithText("tableinfo/0/View");
137     assertTextPresent("logicalDatabase = melatitest, table = tableinfo, troid = 0, method = View");
138   }
139   /**
140    * Fill and click upload.
141    */
142   public void testUpload() { 
143     setScriptingEnabled(false);
144     beginAt("/org.melati.login.Login/admintest");
145     setTextField("field_login", "_administrator_");
146     setTextField("field_password", "FIXME");
147     checkCheckbox("rememberme");
148     submit("action");
149     gotoPage("/" + servletName + "/admintest/");
150 
151     assertTrue("Cannot find file src/main/java/org/melati/admin/static/file.gif",
152         new File("src/main/java/org/melati/admin/static/file.gif").exists());
153     setTextField("file","src/main/java/org/melati/admin/static/file.gif");
154     submit();
155     assertWindowPresent("Upload");
156     assertTrue("Cannot find file pom.xml", new File("pom.xml").exists());
157     setTextField("file", "pom.xml");
158     submit();
159     gotoWindow("Upload");
160     assertTextPresent("<groupId>org.melati</groupId>");
161 
162   }
163   /**
164    * Fill and click upload.
165    */
166   public void testUploadNothing() { 
167     setScriptingEnabled(false);
168     beginAt("/org.melati.login.Login/admintest");
169     setTextField("field_login", "_administrator_");
170     setTextField("field_password", "FIXME");
171     checkCheckbox("rememberme");
172     submit("action");
173     gotoPage("/" + servletName + "/admintest/");
174 
175     //setTextField("file","/dist/melati/melati/src/main/java/org/melati/admin/static/file.gif");
176     submit();
177     gotoWindow("Upload");
178     assertTextPresent("No file was uploaded");
179     
180   }
181 
182 }