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 any 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: F_PortComponentLink.java 7320 2005-09-05 13:33:44Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.service;
025:
026: import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
027:
028: import junit.framework.Test;
029: import junit.framework.TestSuite;
030:
031: import com.meterware.httpunit.*;
032:
033: /**
034: * test case for port component link (service-ref on a colocated webservices instance)
035: * Client doesn't know the ws location in advance.
036: */
037: public class F_PortComponentLink extends JWebServicesTestCase {
038:
039: protected static final String CONTEXT = "/portlink/";
040:
041: public F_PortComponentLink(String name) {
042: super (name, CONTEXT);
043: }
044:
045: public static Test suite() {
046: return new TestSuite(F_PortComponentLink.class);
047: }
048:
049: public void setUp() throws Exception {
050: super .setUp();
051: useEar("port-component-link");
052: }
053:
054: public void tearDown() throws Exception {
055: super .tearDown();
056: }
057:
058: public void testConfiguration() throws Exception {
059: WebResponse wr = wc.getResponse(url + "index.jsp");
060:
061: // check endpoint URL
062: WebLink loc = wr.getLinkWithID("location");
063: assertNotNull(loc);
064: String link = loc.asText();
065: String url = "http://localhost:"
066: + System.getProperty("http.port")
067: + "/endpoint/addressbook";
068: int index = link.indexOf(url);
069: System.out.println("expected URL :" + url);
070: System.out.println("current URL :" + link);
071: assertTrue("endpoint not updated", -1 != index);
072:
073: // check Stub creation
074: WebLink stub = wr.getLinkWithID("stub");
075: assertNotNull("no stub", stub);
076: link = stub.asText();
077: index = link.indexOf("'true'");
078: assertTrue("stub not returned", -1 != index);
079:
080: }
081:
082: public void testResults() throws Exception {
083: WebResponse wr = wc.getResponse(url + "index.jsp");
084:
085: // check return type
086: WebLink type = wr.getLinkWithID("classname");
087: assertNotNull(type);
088: String link = type.asText();
089: int index = link
090: .indexOf("org.objectweb.jonas.jtests.servlets.portlink.Address");
091: assertTrue("bad return type", -1 != index);
092:
093: // check getAddress return
094: WebLink get = wr.getLinkWithID("get");
095: assertNotNull(get);
096: link = get.asText();
097: index = link.indexOf("name : 'JOnAS'");
098: assertTrue("bad name returned", -1 != index);
099: index = link.indexOf("company : 'ObjectWeb Consortium'");
100: assertTrue("bad company returned", -1 != index);
101: index = link.indexOf("version : '4.0'");
102: assertTrue("bad version returned", -1 != index);
103:
104: // check getAddresses return
105: WebLink getAll = wr.getLinkWithID("getAll");
106: assertNotNull(getAll);
107: link = getAll.asText();
108: index = link.indexOf("getAddresses() length : 2");
109: assertTrue("bad length", -1 != index);
110:
111: // check isPresent return
112: WebLink pres = wr.getLinkWithID("present");
113: assertNotNull(pres);
114: link = pres.asText();
115: index = link.indexOf("isPresent(\"JOnAS-Team\") : 'true'");
116: assertTrue("JOnAS Team not found", -1 != index);
117:
118: }
119:
120: public static void main(String args[]) {
121: String testtorun = null;
122: // Get args
123: for (int argn = 0; argn < args.length; argn++) {
124: String s_arg = args[argn];
125: if (s_arg.equals("-n")) {
126: testtorun = args[++argn];
127: }
128: }
129: if (testtorun == null) {
130: junit.textui.TestRunner.run(suite());
131: } else {
132: junit.textui.TestRunner.run(new F_PortComponentLink(
133: testtorun));
134: }
135: }
136:
137: }
|