001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 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: * --------------------------------------------------------------------------
022: * $Id: C_cmp2.java 10557 2007-06-07 09:21:44Z coqp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.examples.clients.cmp2;
027:
028: import junit.framework.TestSuite;
029:
030: import org.objectweb.jonas.examples.util.JExampleTestCase;
031:
032: import com.meterware.httpunit.WebForm;
033: import com.meterware.httpunit.WebResponse;
034:
035: /**
036: * Define a class to test the cmp2 example
037: * Test the three servlet are ok
038: * @author Philippe Coq
039: */
040: public class C_cmp2 extends JExampleTestCase {
041:
042: /**
043: * URL of the cmp2 page
044: */
045: private static final String URL_EARCMP2 = "/cmp2";
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_cmp2(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_cmp2.class);
075: }
076:
077: /**
078: * Setup need for these tests
079: * cmp2 is required
080: * @throws Exception if it fails
081: */
082: protected void setUp() throws Exception {
083: super .setUp();
084: useEar("cmp2");
085: }
086:
087: /**
088: * Constructor with a specified name
089: * @param s name
090: */
091: public C_cmp2(String s) {
092: super (s, URL_EARCMP2);
093: }
094:
095: /**
096: * Test the examples showing 1-to-1 relationship
097: * @throws Exception if an error occurs
098: */
099: public void testFirstServlet() throws Exception {
100:
101: WebResponse wr = wc.getResponse(url);
102:
103: WebForm[] webForms = wr.getForms();
104: WebForm webForm = webForms[0];
105: assertNotNull("There must be a form in the html page", webForm);
106: WebResponse wFormRes = webForm.submit();
107: String txt = wFormRes.getText();
108: if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
109: fail("The example was not ok : " + txt);
110: }
111: }
112:
113: /**
114: * Test the examples showing n-to-1 1-to-n relationship
115: * @throws Exception if an error occurs
116: */
117: public void testSecondServlet() throws Exception {
118:
119: WebResponse wr = wc.getResponse(url);
120:
121: WebForm[] webForms = wr.getForms();
122: WebForm webForm = webForms[1];
123: assertNotNull("There must be a form in the html page", webForm);
124: WebResponse wFormRes = webForm.submit();
125: String txt = wFormRes.getText();
126: if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
127: fail("The example was not ok : " + txt);
128: }
129: }
130:
131: /**
132: * Test the examples using EJB-QL
133: * @throws Exception if an error occurs
134: */
135: public void testThirdServlet() throws Exception {
136:
137: WebResponse wr = wc.getResponse(url);
138:
139: WebForm[] webForms = wr.getForms();
140: WebForm webForm = webForms[2];
141: assertNotNull("There must be a form in the html page", webForm);
142: WebResponse wFormRes = webForm.submit();
143: String txt = wFormRes.getText();
144: if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
145: fail("The example was not ok : " + txt);
146: }
147: }
148:
149: }
|