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   * @author timp
54   * @since 7 Mar 2008
55   *
56   */
57  public class TemplateServletTestTest extends JettyWebTestCase {
58  
59    protected String servletName;
60    /**
61     * @param name
62     */
63    public TemplateServletTestTest(String name) {
64      super(name);
65    }
66  
67    /** 
68     * {@inheritDoc}
69     * @see junit.framework.TestCase#setUp()
70     */
71    protected void setUp() throws Exception {
72      super.setUp();
73      servletName = "/org.melati.test.TemplateServletTest/admintest/";
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);
90      try { 
91        clickLinkWithText("Exception");
92      } catch (FailingHttpStatusCodeException e) { 
93        assertEquals(500, e.getStatusCode());
94      }
95      assertTextPresent("MelatiBugMelatiException");
96    }
97    /**
98     * Click passback link, see exception message.
99     * FIXME Webmacro only test
100    */
101   public void testPassbackException() {
102     setScriptingEnabled(false);
103     beginAt(servletName);
104     clickLinkWithText("?passback=true");
105     assertTextPresent("[Access denied to Melati guest user]");
106   }
107   /**
108    * Click propagate link, get login screen.
109    */
110   public void testPropagateException() {
111     setScriptingEnabled(false);
112     beginAt(servletName);
113     clickLinkWithText("?propagate=true");
114     assertTextPresent("You need to log in");
115     assertTextPresent("You need the capability _administer_ ");
116     setScriptingEnabled(false);
117     beginAt("/org.melati.login.Login/admintest");
118     setTextField("field_login", "_administrator_");
119     setTextField("field_password", "FIXME");
120     checkCheckbox("rememberme");
121     submit();
122     gotoPage(servletName);
123     clickLinkWithText("?propagate=true");
124     assertTextPresent("You are logged in as an Administrator");
125   }
126 
127   /**
128    * Fill and click upload.
129    */
130   public void testUpload() { 
131     setScriptingEnabled(false);
132     beginAt("/org.melati.login.Login/admintest");
133     setTextField("field_login", "_administrator_");
134     setTextField("field_password", "FIXME");
135     checkCheckbox("rememberme");
136     submit();
137     gotoPage(servletName);
138     assertTrue("Cannot find file src/main/java/org/melati/admin/static/file.gif",
139         new File("src/main/java/org/melati/admin/static/file.gif").exists());
140     setTextField("file","src/main/java/org/melati/admin/static/file.gif");
141     submit();
142     assertWindowPresent("Upload");
143     assertTrue("Cannot find file pom.xml", new File("pom.xml").exists());
144     setTextField("file","pom.xml");
145     submit();
146     gotoWindow("Upload");
147     assertTextPresent("<groupId>org.melati</groupId>");
148     
149   }
150 
151   /**
152    * Click Redirect link.
153    */
154   public void testRedirect() {
155     setScriptingEnabled(false);
156     beginAt(servletName);
157     clickLinkWithText("Redirect");
158     assertTextPresent("Melati is a tool");
159   }
160 
161   /**
162    * Click view.
163    */
164   public void testView() { 
165     setScriptingEnabled(false);
166     beginAt(servletName );
167     clickLinkWithText("tableinfo/0/View");
168     assertTextPresent("logicalDatabase = melatitest, table = tableinfo, troid = 0, method = View");
169   }
170 
171 }