001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxws.handler;
019:
020: import java.util.List;
021: import java.util.Map;
022:
023: import javax.jws.HandlerChain;
024: import javax.jws.WebService;
025: import javax.xml.namespace.QName;
026: import javax.xml.ws.handler.Handler;
027: import javax.xml.ws.handler.LogicalHandler;
028: import javax.xml.ws.handler.MessageContext;
029:
030: import org.junit.Assert;
031: import org.junit.Before;
032: import org.junit.Test;
033:
034: public class AnnotationHandlerChainBuilderTest extends Assert {
035:
036: @Before
037: public void setUp() {
038: }
039:
040: @Test
041: public void testFindHandlerChainAnnotation() {
042: HandlerTestImpl handlerTestImpl = new HandlerTestImpl();
043: AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
044: List<Handler> handlers = chainBuilder
045: .buildHandlerChainFromClass(handlerTestImpl.getClass());
046: assertNotNull(handlers);
047: assertEquals(5, handlers.size());
048: assertEquals(TestLogicalHandler.class, handlers.get(0)
049: .getClass());
050: assertEquals(TestLogicalHandler.class, handlers.get(1)
051: .getClass());
052: assertEquals(TestLogicalHandler.class, handlers.get(2)
053: .getClass());
054: assertEquals(TestLogicalHandler.class, handlers.get(3)
055: .getClass());
056: assertEquals(TestProtocolHandler.class, handlers.get(4)
057: .getClass());
058: }
059:
060: @Test
061: public void testFindHandlerChainAnnotationPerPort() {
062: HandlerTestImpl handlerTestImpl = new HandlerTestImpl();
063: AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
064: QName portName = new QName("namespacedoesntsupportyet",
065: "SoapPort1");
066: List<Handler> handlers = chainBuilder
067: .buildHandlerChainFromClass(handlerTestImpl.getClass(),
068: portName);
069: assertNotNull(handlers);
070: assertEquals(5, handlers.size());
071: }
072:
073: public static class TestLogicalHandler implements LogicalHandler {
074: Map config;
075: boolean initCalled;
076:
077: public void close(MessageContext arg0) {
078: }
079:
080: public boolean handleFault(MessageContext arg0) {
081: return false;
082: }
083:
084: public boolean handleMessage(MessageContext arg0) {
085: return false;
086: }
087:
088: public final void init(final Map map) {
089: config = map;
090: initCalled = true;
091: }
092: }
093:
094: public static class TestProtocolHandler implements Handler {
095:
096: public void close(MessageContext arg0) {
097: }
098:
099: public boolean handleFault(MessageContext arg0) {
100: return false;
101: }
102:
103: public boolean handleMessage(MessageContext arg0) {
104: return false;
105: }
106: }
107:
108: @WebService()
109: @HandlerChain(file="./handlers.xml",name="TestHandlerChain")
110: public class HandlerTestImpl {
111:
112: }
113:
114: }
|