KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > service > F_PortComponentLink


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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 any 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  * --------------------------------------------------------------------------
22  * $Id: F_PortComponentLink.java,v 1.6 2005/03/09 10:30:42 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.service;
27
28 import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32
33 import com.meterware.httpunit.*;
34
35 /**
36  * test case for port component link (service-ref on a colocated webservices instance)
37  * Client doesn't know the ws location in advance.
38  */

39 public class F_PortComponentLink extends JWebServicesTestCase {
40
41     protected static final String JavaDoc CONTEXT = "/portlink/";
42
43     public F_PortComponentLink(String JavaDoc name) {
44         super(name, CONTEXT);
45     }
46     
47     public static Test suite() {
48         return new TestSuite(F_PortComponentLink.class);
49     }
50
51     public void setUp() throws Exception JavaDoc {
52         super.setUp();
53         useEar("port-component-link");
54     }
55
56     public void tearDown() throws Exception JavaDoc {
57         super.tearDown();
58     }
59
60     public void testConfiguration() throws Exception JavaDoc {
61         WebResponse wr = wc.getResponse(url + "index.jsp");
62
63         // check endpoint URL
64
WebLink loc = wr.getLinkWithID("location");
65         assertNotNull(loc);
66         String JavaDoc link = loc.asText();
67         String JavaDoc url = "http://localhost:"
68             + System.getProperty("http.port")
69             + "/endpoint/AddressBookPort/AddressBookPort";
70         int index = link.indexOf(url);
71         System.out.println("expected URL :" + url);
72         System.out.println("current URL :" + link);
73         assertTrue("endpoint not updated", -1 != index);
74          
75         // check Stub creation
76
WebLink stub = wr.getLinkWithID("stub");
77         assertNotNull("no stub", stub);
78         link = stub.asText();
79         index = link.indexOf("'true'");
80         assertTrue("stub not returned", -1 != index);
81        
82     }
83
84     public void testResults() throws Exception JavaDoc {
85         WebResponse wr = wc.getResponse(url + "index.jsp");
86
87         // check return type
88
WebLink type = wr.getLinkWithID("classname");
89         assertNotNull(type);
90         String JavaDoc link = type.asText();
91         int index = link.indexOf("org.objectweb.jonas.jtests.servlets.portlink.Address");
92         assertTrue("bad return type", -1 != index);
93          
94         // check getAddress return
95
WebLink get = wr.getLinkWithID("get");
96         assertNotNull(get);
97         link = get.asText();
98         index = link.indexOf("name : 'JOnAS'");
99         assertTrue("bad name returned", -1 != index);
100         index = link.indexOf("company : 'ObjectWeb Consortium'");
101         assertTrue("bad company returned", -1 != index);
102         index = link.indexOf("version : '4.0'");
103         assertTrue("bad version returned", -1 != index);
104          
105         // check getAddresses return
106
WebLink getAll = wr.getLinkWithID("getAll");
107         assertNotNull(getAll);
108         link = getAll.asText();
109         index = link.indexOf("getAddresses() length : 2");
110         assertTrue("bad length", -1 != index);
111
112         // check isPresent return
113
WebLink pres = wr.getLinkWithID("present");
114         assertNotNull(pres);
115         link = pres.asText();
116         index = link.indexOf("isPresent(\"JOnAS-Team\") : 'true'");
117         assertTrue("JOnAS Team not found", -1 != index);
118
119     }
120
121     public static void main (String JavaDoc args[]) {
122         String JavaDoc testtorun = null;
123         // Get args
124
for (int argn = 0; argn < args.length; argn++) {
125             String JavaDoc s_arg = args[argn];
126             if (s_arg.equals("-n")) {
127                 testtorun = args[++argn];
128             }
129         }
130         if (testtorun == null) {
131             junit.textui.TestRunner.run(suite());
132         } else {
133             junit.textui.TestRunner.run(new F_PortComponentLink(testtorun));
134         }
135     }
136
137 }
138
Popular Tags