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: * --------------------------------------------------------------------------
022: * $Id: SampleCluster2Test.java 8421 2006-06-02 12:23:24Z duvauchn $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.cluster.test;
025:
026: import java.io.IOException;
027: import java.net.MalformedURLException;
028:
029: import org.xml.sax.SAXException;
030:
031: import com.meterware.httpunit.GetMethodWebRequest;
032: import com.meterware.httpunit.WebConversation;
033: import com.meterware.httpunit.WebRequest;
034: import com.meterware.httpunit.WebResponse;
035:
036: import junit.framework.TestCase;
037: import junit.framework.TestSuite;
038:
039: /**
040: * the aim of this class is to check the different calls made in sampleCluster2
041: * example.
042: * @author Nicolas Duvauchel
043: */
044: public class SampleCluster2Test extends TestCase {
045:
046: /**
047: * the link with the web page
048: */
049: private static WebConversation conversation = null;
050:
051: /**
052: * @param args
053: */
054: public static void main(String args[]) {
055: junit.textui.TestRunner.run(suite());
056: }
057:
058: /**
059: * @return the test suite
060: */
061: public static TestSuite suite() {
062: return new TestSuite(SampleCluster2Test.class);
063: }
064:
065: /**
066: * @param s
067: */
068: public SampleCluster2Test(String s) {
069: super (s);
070: }
071:
072: /**
073: * set up parameters for the tests
074: */
075: protected void setUp() throws Exception {
076: if (conversation == null) {
077: System.out.println("setting up conversation.");
078: conversation = new WebConversation();
079: }
080: }
081:
082: /**
083: * test if the page is accessible
084: * @throws Exception
085: */
086: public void testReachable() throws Exception {
087:
088: try {
089: WebRequest request = new GetMethodWebRequest(
090: "http://localhost/sampleCluster2");
091:
092: WebResponse response = conversation.getResponse(request);
093: System.out.println(response.getText());
094: } catch (Exception e) {
095: fail("on test Reachable: " + e);
096: }
097:
098: }
099:
100: /**
101: * test and create a session
102: * @throws Exception
103: */
104: public void testSession() throws Exception {
105: try {
106: WebRequest request = new GetMethodWebRequest(
107: "http://localhost/sampleCluster2/servlet/session");
108:
109: WebResponse response = conversation.getResponse(request);
110: System.out.println(response.getText());
111: } catch (Exception e) {
112: fail("on test Session: " + e);
113: }
114: }
115:
116: /**
117: * test and check the session
118: * @throws Exception
119: */
120: public void testCheck() throws Exception {
121: try {
122: WebRequest request = new GetMethodWebRequest(
123: "http://localhost/sampleCluster2/servlet/check");
124:
125: WebResponse response = conversation.getResponse(request);
126: System.out.println(response.getText());
127: } catch (Exception e) {
128: fail("on test Check: " + e);
129: }
130: }
131:
132: /**
133: * test and release the session
134: * @throws Exception
135: */
136: public void testRelease() throws Exception {
137: try {
138: WebRequest request = new GetMethodWebRequest(
139: "http://localhost/sampleCluster2/servlet/release");
140:
141: WebResponse response = conversation.getResponse(request);
142: System.out.println(response.getText());
143: } catch (Exception e) {
144: fail("on test Release: " + e);
145: }
146: }
147:
148: /**
149: * test the exception
150: * @throws Exception
151: */
152: public void testException() throws Exception {
153: try {
154: WebRequest request = new GetMethodWebRequest(
155: "http://localhost/sampleCluster2/servlet/exception");
156:
157: WebResponse response = conversation.getResponse(request);
158: System.out.println(response.getText());
159: } catch (Exception e) {
160: fail("on test Exception: " + e);
161: }
162: }
163:
164: }
|