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 BeforeAfterTest extends TestCase { 41 42 public void testBeforeAfter() { 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 ("First")); 58 hm.setHandler(h1); 59 hm.setName(new QName ("H1")); 60 PhaseRule rule = new PhaseRule(); 61 rule.setPhaseName("PhaseA"); 62 hm.setRules(rule); 63 ph.addHandler(hm); 64 65 HandlerDescription hm1 = new HandlerDescription(); 66 hm1.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers"); 67 Handler h2 = new PhaseRuleHandlers(); 68 ((PhaseRuleHandlers) h2).setName(new QName ("Forth")); 69 h2.init(hm1); 70 hm1.setHandler(h2); 71 hm1.setName(new QName ("H2")); 72 PhaseRule rule1 = new PhaseRule(); 73 rule1.setPhaseName("PhaseA"); 74 hm1.setRules(rule1); 75 ph.addHandler(hm1); 76 77 78 HandlerDescription hm3 = new HandlerDescription(); 79 hm3.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers"); 80 Handler h3 = new PhaseRuleHandlers(); 81 ((PhaseRuleHandlers) h3).setName(new QName ("Second")); 82 h3.init(hm3); 83 hm3.setHandler(h3); 84 hm3.setName(new QName ("H3")); 85 PhaseRule rule3 = new PhaseRule(); 86 rule3.setPhaseName("PhaseA"); 87 rule3.setAfter("H1"); 88 hm3.setRules(rule3); 89 ph.addHandler(hm3); 90 91 HandlerDescription hm4 = new HandlerDescription(); 92 hm4.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers"); 93 Handler h4 = new PhaseRuleHandlers(); 94 ((PhaseRuleHandlers) h4).setName(new QName ("Third")); 95 h4.init(hm4); 96 hm4.setHandler(h4); 97 hm4.setName(new QName ("H4")); 98 PhaseRule rule4 = new PhaseRule(); 99 rule4.setPhaseName("PhaseA"); 100 rule4.setAfter("H1"); 101 rule4.setBefore("H2"); 102 hm4.setRules(rule4); 103 ph.addHandler(hm4); 104 105 ArrayList handlers = p1.getHandlers(); 106 107 for (int i = 0; i < handlers.size(); i++) { 108 Handler handler = (Handler) handlers.get(i); 109 System.out.println("handler = " + handler.getName()); 110 } 111 112 Handler handler = (Handler) handlers.get(0); 113 if(!handler.getName().equals(new QName ("First"))){ 114 fail("Computed Hnadler order is wrong "); 115 } 116 handler = (Handler) handlers.get(1); 117 if(!handler.getName().equals(new QName ("Third"))){ 118 fail("Computed Hnadler order is wrong "); 119 } 120 handler = (Handler) handlers.get(2); 121 if(!handler.getName().equals(new QName ("Second"))){ 122 fail("Computed Hnadler order is wrong "); 123 } 124 125 handler = (Handler) handlers.get(3); 126 if(!handler.getName().equals(new QName ("Forth"))){ 127 fail("Computed Hnadler order is wrong "); 128 } 129 130 } catch (AxisFault axisFault) { 131 return; 132 } 133 134 } 135 } 136 | Popular Tags |