1 package org.apache.axis2.phaserule; 2 3 import junit.framework.TestCase; 4 import org.apache.axis2.context.ConfigurationContext; 5 import org.apache.axis2.context.MessageContext; 6 import org.apache.axis2.description.HandlerDescription; 7 import org.apache.axis2.description.PhaseRule; 8 import org.apache.axis2.engine.AxisConfigurationImpl; 9 import org.apache.axis2.engine.AxisFault; 10 import org.apache.axis2.engine.Handler; 11 import org.apache.axis2.engine.Phase; 12 import org.apache.axis2.phaseresolver.PhaseHolder; 13 14 import javax.xml.namespace.QName ; 15 import java.util.ArrayList ; 16 17 34 35 40 public class SingleHandlerPhaseTest extends TestCase { 41 42 public void testSingleHandler() { 43 try { 44 ArrayList phases = new ArrayList (); 45 Phase p1 = new Phase("PhaseA"); 46 phases.add(p1); 47 Phase p2 = new Phase("PhaseB"); 48 phases.add(p2); 49 50 MessageContext msg = new MessageContext(new ConfigurationContext(new AxisConfigurationImpl())); 51 52 PhaseHolder ph = new PhaseHolder(phases); 53 HandlerDescription hm = new HandlerDescription(); 54 hm.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers"); 55 Handler h1 = new PhaseRuleHandlers(); 56 h1.init(hm); 57 ((PhaseRuleHandlers) h1).setName(new QName ("PhaseFirstHnadler")); 58 hm.setHandler(h1); 59 hm.setName(new QName ("H1")); 60 PhaseRule rule = new PhaseRule(); 61 rule.setPhaseName("PhaseA"); 62 rule.setPhaseFirst(true); 63 rule.setPhaseLast(true); 64 hm.setRules(rule); 65 ph.addHandler(hm); 66 67 HandlerDescription hm1 = new HandlerDescription(); 68 hm1.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers"); 69 Handler h2 = new PhaseRuleHandlers(); 70 ((PhaseRuleHandlers) h2).setName(new QName ("Second Handler")); 71 h2.init(hm1); 72 hm1.setHandler(h2); 73 hm1.setName(new QName ("H2")); 74 PhaseRule rule1 = new PhaseRule(); 75 rule1.setPhaseName("PhaseA"); 76 rule1.setAfter("H1"); 77 hm1.setRules(rule1); 78 ph.addHandler(hm1); 79 p1.invoke(msg); 80 fail("This should fail with : can only have one handler, since there is a " + 81 "handler with both phaseFirst and PhaseLast true "); 82 } catch (AxisFault axisFault) { 83 return; 84 } 85 } 86 } 87 | Popular Tags |