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.axis2;
017:
018: import org.apache.geronimo.testsupport.TestSupport;
019: import org.apache.geronimo.xbeans.javaee.HandlerChainsDocument;
020: import org.apache.geronimo.xbeans.javaee.HandlerChainsType;
021:
022: import javax.xml.namespace.QName;
023: import javax.xml.ws.handler.Handler;
024: import javax.xml.ws.handler.PortInfo;
025: import java.io.InputStream;
026: import java.util.List;
027:
028: public class Axis2HandlerResolverTest extends TestSupport {
029:
030: public void testBasic() throws Exception {
031: InputStream in = getClass()
032: .getResourceAsStream("/handlers.xml");
033: assertTrue(in != null);
034: HandlerChainsType handlerChains = toHandlerChains(in);
035: assertEquals(3, handlerChains.getHandlerChainArray().length);
036:
037: Axis2HandlerResolver resolver = new Axis2HandlerResolver(
038: getClass().getClassLoader(), getClass(), handlerChains,
039: null);
040:
041: List<Handler> handlers = null;
042:
043: handlers = resolver.getHandlerChain(new TestPortInfo(null,
044: null, null));
045: assertEquals(3, handlers.size());
046: }
047:
048: public void testServiceMatching() throws Exception {
049: InputStream in = getClass().getResourceAsStream(
050: "/handlers_service.xml");
051: assertTrue(in != null);
052: HandlerChainsType handlerChains = toHandlerChains(in);
053: assertEquals(3, handlerChains.getHandlerChainArray().length);
054:
055: Axis2HandlerResolver resolver = new Axis2HandlerResolver(
056: getClass().getClassLoader(), getClass(), handlerChains,
057: null);
058:
059: List<Handler> handlers = null;
060:
061: handlers = resolver.getHandlerChain(new TestPortInfo(null,
062: null, null));
063: assertEquals(0, handlers.size());
064:
065: QName serviceName1 = new QName("http://foo", "Bar");
066: handlers = resolver.getHandlerChain(new TestPortInfo(null,
067: null, serviceName1));
068: assertEquals(1, handlers.size());
069:
070: QName serviceName2 = new QName("http://foo", "Foo");
071: handlers = resolver.getHandlerChain(new TestPortInfo(null,
072: null, serviceName2));
073: assertEquals(2, handlers.size());
074:
075: QName serviceName3 = new QName("http://foo", "FooBar");
076: handlers = resolver.getHandlerChain(new TestPortInfo(null,
077: null, serviceName3));
078: assertEquals(1, handlers.size());
079:
080: QName serviceName4 = new QName("http://foo", "BarFoo");
081: handlers = resolver.getHandlerChain(new TestPortInfo(null,
082: null, serviceName4));
083: assertEquals(0, handlers.size());
084: }
085:
086: public void testBindingMatching() throws Exception {
087: InputStream in = getClass().getResourceAsStream(
088: "/handlers_bindings.xml");
089: assertTrue(in != null);
090: HandlerChainsType handlerChains = toHandlerChains(in);
091: assertEquals(3, handlerChains.getHandlerChainArray().length);
092:
093: Axis2HandlerResolver resolver = new Axis2HandlerResolver(
094: getClass().getClassLoader(), getClass(), handlerChains,
095: null);
096:
097: List<Handler> handlers = null;
098:
099: handlers = resolver.getHandlerChain(new TestPortInfo(null,
100: null, null));
101: assertEquals(0, handlers.size());
102:
103: handlers = resolver.getHandlerChain(new TestPortInfo(
104: "##SOAP12_HTTP", null, null));
105: assertEquals(0, handlers.size());
106:
107: handlers = resolver.getHandlerChain(new TestPortInfo(
108: "##SOAP11_HTTP", null, null));
109: assertEquals(2, handlers.size());
110:
111: handlers = resolver.getHandlerChain(new TestPortInfo(
112: "##SOAP11_HTTP_MTOM", null, null));
113: assertEquals(1, handlers.size());
114: }
115:
116: public void testPortMatching() throws Exception {
117: InputStream in = getClass().getResourceAsStream(
118: "/handlers_port.xml");
119: assertTrue(in != null);
120: HandlerChainsType handlerChains = toHandlerChains(in);
121: assertEquals(3, handlerChains.getHandlerChainArray().length);
122:
123: Axis2HandlerResolver resolver = new Axis2HandlerResolver(
124: getClass().getClassLoader(), getClass(), handlerChains,
125: null);
126:
127: List<Handler> handlers = null;
128:
129: handlers = resolver.getHandlerChain(new TestPortInfo(null,
130: null, null));
131: assertEquals(0, handlers.size());
132:
133: QName portName1 = new QName("http://foo", "Bar");
134: handlers = resolver.getHandlerChain(new TestPortInfo(null,
135: portName1, null));
136: assertEquals(1, handlers.size());
137:
138: QName portName2 = new QName("http://foo", "Foo");
139: handlers = resolver.getHandlerChain(new TestPortInfo(null,
140: portName2, null));
141: assertEquals(2, handlers.size());
142:
143: QName portName3 = new QName("http://foo", "FooBar");
144: handlers = resolver.getHandlerChain(new TestPortInfo(null,
145: portName3, null));
146: assertEquals(1, handlers.size());
147:
148: QName portName4 = new QName("http://foo", "BarFoo");
149: handlers = resolver.getHandlerChain(new TestPortInfo(null,
150: portName4, null));
151: assertEquals(0, handlers.size());
152: }
153:
154: public void testMixedMatching() throws Exception {
155: InputStream in = getClass().getResourceAsStream(
156: "/handlers_mixed.xml");
157: assertTrue(in != null);
158: HandlerChainsType handlerChains = toHandlerChains(in);
159: assertEquals(3, handlerChains.getHandlerChainArray().length);
160:
161: Axis2HandlerResolver resolver = new Axis2HandlerResolver(
162: getClass().getClassLoader(), getClass(), handlerChains,
163: null);
164:
165: List<Handler> handlers = null;
166:
167: handlers = resolver.getHandlerChain(new TestPortInfo(null,
168: null, null));
169: assertEquals(0, handlers.size());
170:
171: QName serviceName1 = new QName("http:/foo", "Bar");
172: QName portName1 = new QName("http://foo", "FooBar");
173: String binding1 = "##XML_HTTP";
174: handlers = resolver.getHandlerChain(new TestPortInfo(binding1,
175: portName1, serviceName1));
176: assertEquals(3, handlers.size());
177:
178: String binding2 = "##SOAP11_HTTP";
179: handlers = resolver.getHandlerChain(new TestPortInfo(binding2,
180: portName1, serviceName1));
181: assertEquals(2, handlers.size());
182:
183: QName serviceName2 = new QName("http://foo", "Baaz");
184: QName portName2 = new QName("http://foo", "Baaz");
185: handlers = resolver.getHandlerChain(new TestPortInfo(binding1,
186: portName2, serviceName2));
187: assertEquals(1, handlers.size());
188: }
189:
190: private static HandlerChainsType toHandlerChains(InputStream input)
191: throws Exception {
192: return HandlerChainsDocument.Factory.parse(input)
193: .getHandlerChains();
194: }
195:
196: private static class TestPortInfo implements PortInfo {
197:
198: private String bindingID;
199: private QName portName;
200: private QName serviceName;
201:
202: public TestPortInfo(String bindingID, QName portName,
203: QName serviceName) {
204: this .bindingID = bindingID;
205: this .portName = portName;
206: this .serviceName = serviceName;
207: }
208:
209: public String getBindingID() {
210: return this .bindingID;
211: }
212:
213: public QName getPortName() {
214: return this .portName;
215: }
216:
217: public QName getServiceName() {
218: return this.serviceName;
219: }
220:
221: }
222:
223: }
|