001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Guillaume Sauthier
022: * --------------------------------------------------------------------------
023: * $Id: C_hibernate.java 10557 2007-06-07 09:21:44Z coqp $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.examples.clients.hibernate;
028:
029: import junit.framework.TestSuite;
030:
031: import org.objectweb.jonas.examples.util.JExampleTestCase;
032:
033: import com.meterware.httpunit.WebResponse;
034:
035: /**
036: * Define a class to test the Alarm example
037: * Test authentication, and check the sample is ok
038: * @author Florent Benoit
039: */
040: public class C_hibernate extends JExampleTestCase {
041:
042: /**
043: * URL of the hibernate page
044: */
045: private static final String URL_HIBERNATE = "/hibernate-sample/testHibernate";
046:
047: /**
048: * Main method
049: * @param args the arguments
050: */
051: public static void main(String[] args) {
052:
053: String testtorun = null;
054: // Get args
055: for (int argn = 0; argn < args.length; argn++) {
056: String sArg = args[argn];
057: if (sArg.equals("-n")) {
058: testtorun = args[++argn];
059: }
060: }
061:
062: if (testtorun == null) {
063: junit.textui.TestRunner.run(suite());
064: } else {
065: junit.textui.TestRunner.run(new C_hibernate(testtorun));
066: }
067: }
068:
069: /**
070: * Get a new TestSuite for this class
071: * @return a new TestSuite for this class
072: */
073: public static TestSuite suite() {
074: return new TestSuite(C_hibernate.class);
075: }
076:
077: /**
078: * Setup need for these tests
079: * earsample is required
080: * @throws Exception if it fails
081: */
082: protected void setUp() throws Exception {
083: super .setUp();
084: useWar("hibernate-sample");
085: }
086:
087: /**
088: * Constructor with a specified name
089: * @param s name
090: */
091: public C_hibernate(String s) {
092: super (s, URL_HIBERNATE);
093: }
094:
095: /**
096: * Try to log in without authentication
097: * @throws Exception if an error occurs
098: */
099: public void testAccessHibernatePage() throws Exception {
100: WebResponse wr = wc.getResponse(url);
101: String 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 "
106: + this.url);
107: }
108:
109: }
110:
111: }
|