KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > ContainerTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.jetty6;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.net.HttpURLConnection JavaDoc;
23 import java.net.URL JavaDoc;
24
25 import org.apache.geronimo.jetty6.app.MockWebServiceContainer;
26
27 /**
28  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
29  */

30 public class ContainerTest extends AbstractWebModuleTest {
31
32     public void testHTTPConnector() throws Exception JavaDoc {
33
34         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678").openConnection();
35         try {
36             connection.getInputStream();
37             fail();
38         } catch (Exception JavaDoc e) {
39             // 404 proves we spoke to the server even if we didn't get anything
40
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
41             connection.disconnect();
42         }
43     }
44
45     public void testWebServiceHandler() throws Exception JavaDoc {
46
47         String JavaDoc contextPath = "/foo/webservice.ws";
48         MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
49         container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl);
50
51         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678" + contextPath).openConnection();
52         try {
53             BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
54             assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
55             assertEquals("Hello World", reader.readLine());
56         } finally {
57             connection.disconnect();
58         }
59         container.removeWebService(contextPath);
60         connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678" + contextPath).openConnection();
61         try {
62             connection.getInputStream();
63             fail();
64         } catch (Exception JavaDoc e) {
65             // see if we removed the ws.
66
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
67             connection.disconnect();
68         }
69     }
70     public void test2WebServiceHandlers() throws Exception JavaDoc {
71
72         String JavaDoc contextPath = "/foo/webservice.ws";
73         MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
74         container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl);
75
76         String JavaDoc contextPath2 = "/bar/webservice.ws";
77         MockWebServiceContainer webServiceInvoker2 = new MockWebServiceContainer();
78         container.addWebService(contextPath2, null, webServiceInvoker2, null, null, null, null,cl);
79
80         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678" + contextPath).openConnection();
81         try {
82             BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
83             assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
84             assertEquals("Hello World", reader.readLine());
85         } finally {
86             connection.disconnect();
87         }
88         container.removeWebService(contextPath);
89         connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678" + contextPath).openConnection();
90         try {
91             connection.getInputStream();
92             fail();
93         } catch (Exception JavaDoc e) {
94             // see if we removed the ws.
95
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
96             connection.disconnect();
97         }
98     }
99
100 }
101
Popular Tags