001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.jetty6;
017:
018: import java.io.BufferedReader;
019: import java.io.InputStreamReader;
020: import java.net.HttpURLConnection;
021: import java.net.URL;
022:
023: import org.apache.geronimo.jetty6.app.MockWebServiceContainer;
024:
025: /**
026: * @version $Rev: 487617 $ $Date: 2006-12-15 10:42:11 -0800 (Fri, 15 Dec 2006) $
027: */
028: public class ContainerTest extends AbstractWebModuleTest {
029:
030: public void testHTTPConnector() throws Exception {
031:
032: HttpURLConnection connection = (HttpURLConnection) new URL(
033: "http://localhost:5678").openConnection();
034: try {
035: connection.getInputStream();
036: fail();
037: } catch (Exception e) {
038: // 404 proves we spoke to the server even if we didn't get anything
039: assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection
040: .getResponseCode());
041: connection.disconnect();
042: }
043: }
044:
045: public void testWebServiceHandler() throws Exception {
046:
047: String contextPath = "/foo/webservice.ws";
048: MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
049: container.addWebService(contextPath, null, webServiceInvoker,
050: null, null, null, null, cl);
051:
052: HttpURLConnection connection = (HttpURLConnection) new URL(
053: "http://localhost:5678" + contextPath).openConnection();
054: try {
055: BufferedReader reader = new BufferedReader(
056: new InputStreamReader(connection.getInputStream()));
057: assertEquals(HttpURLConnection.HTTP_OK, connection
058: .getResponseCode());
059: assertEquals("Hello World", reader.readLine());
060: } finally {
061: connection.disconnect();
062: }
063: container.removeWebService(contextPath);
064: connection = (HttpURLConnection) new URL(
065: "http://localhost:5678" + contextPath).openConnection();
066: try {
067: connection.getInputStream();
068: fail();
069: } catch (Exception e) {
070: // see if we removed the ws.
071: assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection
072: .getResponseCode());
073: connection.disconnect();
074: }
075: }
076:
077: public void test2WebServiceHandlers() throws Exception {
078:
079: String contextPath = "/foo/webservice.ws";
080: MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
081: container.addWebService(contextPath, null, webServiceInvoker,
082: null, null, null, null, cl);
083:
084: String contextPath2 = "/bar/webservice.ws";
085: MockWebServiceContainer webServiceInvoker2 = new MockWebServiceContainer();
086: container.addWebService(contextPath2, null, webServiceInvoker2,
087: null, null, null, null, cl);
088:
089: HttpURLConnection connection = (HttpURLConnection) new URL(
090: "http://localhost:5678" + contextPath).openConnection();
091: try {
092: BufferedReader reader = new BufferedReader(
093: new InputStreamReader(connection.getInputStream()));
094: assertEquals(HttpURLConnection.HTTP_OK, connection
095: .getResponseCode());
096: assertEquals("Hello World", reader.readLine());
097: } finally {
098: connection.disconnect();
099: }
100: container.removeWebService(contextPath);
101: connection = (HttpURLConnection) new URL(
102: "http://localhost:5678" + contextPath).openConnection();
103: try {
104: connection.getInputStream();
105: fail();
106: } catch (Exception e) {
107: // see if we removed the ws.
108: assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection
109: .getResponseCode());
110: connection.disconnect();
111: }
112: }
113:
114: }
|