KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > examples > clients > hibernate > F_Hibernate


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Guillaume Sauthier
22  * --------------------------------------------------------------------------
23  * $Id$
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.examples.clients.hibernate;
28
29 import junit.framework.TestSuite;
30
31 import org.objectweb.jonas.examples.util.JExampleTestCase;
32
33 import com.meterware.httpunit.WebResponse;
34
35 /**
36  * Define a class to test the Alarm example
37  * Test authentication, and check the sample is ok
38  * @author Florent Benoit
39  */

40 public class F_Hibernate extends JExampleTestCase {
41
42     /**
43      * URL of the hibernate page
44      */

45     private static final String JavaDoc URL_HIBERNATE = "/hibernate-sample/testHibernate";
46
47     /**
48      * Main method
49      * @param args the arguments
50      */

51     public static void main(String JavaDoc[] args) {
52
53         String JavaDoc testtorun = null;
54         // Get args
55
for (int argn = 0; argn < args.length; argn++) {
56             String JavaDoc sArg = args[argn];
57             if (sArg.equals("-n")) {
58                 testtorun = args[++argn];
59             }
60         }
61
62         if (testtorun == null) {
63             junit.textui.TestRunner.run(suite());
64         } else {
65             junit.textui.TestRunner.run(new F_Hibernate(testtorun));
66         }
67     }
68
69     /**
70      * Get a new TestSuite for this class
71      * @return a new TestSuite for this class
72      */

73     public static TestSuite suite() {
74         return new TestSuite(F_Hibernate.class);
75     }
76
77     /**
78      * Setup need for these tests
79      * earsample is required
80      * @throws Exception if it fails
81      */

82     protected void setUp() throws Exception JavaDoc {
83         super.setUp();
84         useWar("hibernate-sample");
85     }
86
87     /**
88      * Constructor with a specified name
89      * @param s name
90      */

91     public F_Hibernate(String JavaDoc s) {
92         super(s, URL_HIBERNATE);
93     }
94
95     /**
96      * Try to log in without authentication
97      * @throws Exception if an error occurs
98      */

99     public void testAccessHibernatePage() throws Exception JavaDoc {
100             WebResponse wr = wc.getResponse(url);
101             String JavaDoc page = wr.getText();
102
103             // check "Servlet is OK"
104
if (page.indexOf("Servlet is OK") == -1) {
105                 fail("Missing 'Servlet is OK' ending text. Check on " + this.url);
106             }
107
108     }
109
110 }
111
Popular Tags