KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > phaserule > BeforeWithNoFirstHandlerTest


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 JavaDoc;
15 import java.util.ArrayList JavaDoc;
16
17 /*
18  * Copyright 2004,2005 The Apache Software Foundation.
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License");
21  * you may not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  * http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS,
28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  *
32  *
33  */

34
35 /**
36  * Author : Deepal Jayasinghe
37  * Date: May 20, 2005
38  * Time: 3:04:42 PM
39  */

40 public class BeforeWithNoFirstHandlerTest extends TestCase{
41     public void testBeforewithNoFirst() throws AxisFault {
42         ArrayList JavaDoc phases = new ArrayList JavaDoc();
43         Phase p1 = new Phase("PhaseA");
44         phases.add(p1);
45         Phase p2 = new Phase("PhaseB");
46         phases.add(p2);
47
48         MessageContext msg = new MessageContext(new ConfigurationContext(new AxisConfigurationImpl()));
49
50         PhaseHolder ph = new PhaseHolder(phases);
51
52
53         HandlerDescription hm1 = new HandlerDescription();
54         hm1.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers");
55         Handler h2 = new PhaseRuleHandlers();
56         ((PhaseRuleHandlers) h2).setName(new QName JavaDoc("Second"));
57         h2.init(hm1);
58         hm1.setHandler(h2);
59         hm1.setName(new QName JavaDoc("H2"));
60         PhaseRule rule1 = new PhaseRule();
61         rule1.setPhaseName("PhaseA");
62         rule1.setBefore("H1");
63         hm1.setRules(rule1);
64         ph.addHandler(hm1);
65
66         HandlerDescription hm = new HandlerDescription();
67         hm.setClassName("org.apache.axis2.phaserule.PhaseRuleHandlers");
68         Handler h1 = new PhaseRuleHandlers();
69         h1.init(hm);
70         ((PhaseRuleHandlers) h1).setName(new QName JavaDoc("First"));
71         hm.setHandler(h1);
72         hm.setName(new QName JavaDoc("H1"));
73         PhaseRule rule = new PhaseRule();
74         rule.setPhaseName("PhaseA");
75         hm.setRules(rule);
76         ph.addHandler(hm);
77
78         ArrayList JavaDoc handlers = p1.getHandlers();
79         Handler handler = (Handler) handlers.get(0);
80         if(!handler.getName().equals(new QName JavaDoc("Second"))){
81             fail("Computed Hnadler order is wrong ");
82         }
83         handler = (Handler) handlers.get(1);
84         if(!handler.getName().equals(new QName JavaDoc("First"))){
85             fail("Computed Hnadler order is wrong ");
86         }
87         p1.invoke(msg);
88     }
89 }
90
Popular Tags