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: */
019: package org.apache.axis2.phaserule;
020:
021: import org.apache.axis2.AbstractTestCase;
022: import org.apache.axis2.description.HandlerDescription;
023: import org.apache.axis2.engine.AxisConfiguration;
024: import org.apache.axis2.engine.DispatchPhase;
025: import org.apache.axis2.engine.Handler;
026: import org.apache.axis2.engine.Phase;
027: import org.apache.axis2.phaseresolver.PhaseHolder;
028:
029: import java.util.ArrayList;
030:
031: public class AddingHandlerToEachPhaseTest extends AbstractTestCase {
032: AxisConfiguration axisConfig;
033:
034: public AddingHandlerToEachPhaseTest(String testName) {
035: super (testName);
036: }
037:
038: public void testPhaseRules() throws Exception {
039: //TODO fix me
040: axisConfig = new AxisConfiguration();
041: ArrayList inPhase = axisConfig.getInFlowPhases();
042: Phase transportIN = new Phase("TransportIn");
043: Phase preDispatch = new Phase("PreDispatch");
044: DispatchPhase dispatchPhase = new DispatchPhase();
045: //
046: dispatchPhase.setName("Dispatch");
047: inPhase.add(transportIN);
048: inPhase.add(preDispatch);
049: inPhase.add(dispatchPhase);
050:
051: HandlerDescription hm = new HandlerDescription();
052: hm.setClassName("org.apache.axis2.handlers.AbstractHandler");
053: Handler h1 = new PhaseRuleHandler();
054: hm.setHandler(h1);
055: hm.getRules().setPhaseName("*");
056:
057: PhaseHolder ph = new PhaseHolder(inPhase);
058: ph.addHandler(hm);
059: boolean found;
060: for (int i = 0; i < inPhase.size(); i++) {
061: found = false;
062: Phase phase = (Phase) inPhase.get(i);
063: ArrayList hnadles = phase.getHandlers();
064: for (int j = 0; j < hnadles.size(); j++) {
065: Handler handler = (Handler) hnadles.get(j);
066: if (h1.equals(handler)) {
067: found = true;
068: }
069: }
070: if (!found) {
071: fail("Some thing has gone wrong hnadler does not exit in the phase :"
072: + phase.getPhaseName());
073: }
074: }
075: }
076:
077: public void testPhaseRulesWithPhaseFirst() throws Exception {
078: super .setUp();
079: //TODO fix me
080: axisConfig = new AxisConfiguration();
081: ArrayList inPhase = axisConfig.getInFlowPhases();
082: Phase transportIN = new Phase("TransportIn");
083: Phase preDispatch = new Phase("PreDispatch");
084: DispatchPhase dispatchPhase = new DispatchPhase();
085: //
086: dispatchPhase.setName("Dispatch");
087: inPhase.add(transportIN);
088: inPhase.add(preDispatch);
089: inPhase.add(dispatchPhase);
090:
091: HandlerDescription hm = new HandlerDescription();
092: hm.setClassName("org.apache.axis2.handlers.AbstractHandler");
093: Handler h1 = new PhaseRuleHandler();
094: hm.setHandler(h1);
095: hm.getRules().setPhaseName("*");
096: hm.getRules().setPhaseFirst(true);
097:
098: PhaseHolder ph = new PhaseHolder(inPhase);
099: ph.addHandler(hm);
100: for (int i = 0; i < inPhase.size(); i++) {
101: Phase phase = (Phase) inPhase.get(i);
102: ArrayList hnadles = phase.getHandlers();
103: Handler handler = (Handler) hnadles.get(0);
104: if (!h1.equals(handler)) {
105: fail("Some thing has gone wrong hnadler does not exit as phase "
106: + "first handler the phase :"
107: + phase.getPhaseName());
108: }
109: }
110: }
111:
112: public void testPhaseRulesWithAfter() throws Exception {
113: //TODO fix me
114: axisConfig = new AxisConfiguration();
115: ArrayList inPhase = axisConfig.getInFlowPhases();
116: Phase transportIN = new Phase("TransportIn");
117: Phase preDispatch = new Phase("PreDispatch");
118: DispatchPhase dispatchPhase = new DispatchPhase();
119: //
120: dispatchPhase.setName("Dispatch");
121: inPhase.add(transportIN);
122: inPhase.add(preDispatch);
123: inPhase.add(dispatchPhase);
124:
125: HandlerDescription hm = new HandlerDescription();
126: hm.setClassName("org.apache.axis2.handlers.AbstractHandler");
127: Handler h1 = new PhaseRuleHandler();
128: hm.setHandler(h1);
129: hm.getRules().setPhaseName("*");
130: hm.getRules().setPhaseFirst(true);
131:
132: PhaseHolder ph = new PhaseHolder(inPhase);
133: ph.addHandler(hm);
134: for (int i = 0; i < inPhase.size(); i++) {
135: Phase phase = (Phase) inPhase.get(i);
136: ArrayList hnadles = phase.getHandlers();
137: Handler handler = (Handler) hnadles.get(0);
138: assertNull(handler.getHandlerDesc().getRules().getAfter());
139: }
140: }
141: }
|