KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > context > ContextHierarchyTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.context;
17
18 import junit.framework.TestCase;
19 import org.apache.axis2.description.OperationDescription;
20 import org.apache.axis2.description.ParameterImpl;
21 import org.apache.axis2.description.ServiceDescription;
22 import org.apache.axis2.engine.AxisConfiguration;
23 import org.apache.axis2.engine.AxisConfigurationImpl;
24 import org.apache.axis2.engine.AxisFault;
25
26 import javax.xml.namespace.QName JavaDoc;
27
28 /**
29  * @author srinath
30  *
31  * To change the template for this generated type comment go to
32  * Window>Preferences>Java>Code Generation>Code and Comments
33  */

34 public class ContextHierarchyTest extends TestCase {
35     private OperationDescription operationDescription;
36     private ServiceDescription serviceDescription;
37     private AxisConfiguration axisConfiguration;
38
39     public ContextHierarchyTest(String JavaDoc arg0) {
40         super(arg0);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         operationDescription = new OperationDescription(new QName JavaDoc("Temp"));
45         serviceDescription = new ServiceDescription(new QName JavaDoc("Temp"));
46         axisConfiguration = new AxisConfigurationImpl();
47         serviceDescription.addOperation(operationDescription);
48         axisConfiguration.addService(serviceDescription);
49     }
50
51     public void testCompleteHiracy() throws AxisFault {
52         ConfigurationContext configurationContext =
53             new ConfigurationContext(axisConfiguration);
54         ServiceContext serviceCOntext =
55             configurationContext.createServiceContext(
56                 serviceDescription.getName());
57         MessageContext msgctx =
58             new MessageContext(configurationContext);
59         OperationContext opContext =
60             operationDescription.findOperationContext(
61                 msgctx,
62                 serviceCOntext);
63         msgctx.setServiceContext(serviceCOntext);
64
65         //test the complte Hisracy built
66
assertEquals(msgctx.getParent(), opContext);
67         assertEquals(opContext.getParent(), serviceCOntext);
68         assertEquals(serviceCOntext.getParent(), configurationContext);
69
70         String JavaDoc key1 = "key1";
71         String JavaDoc value1 = "Val1";
72         String JavaDoc value2 = "value2";
73         String JavaDoc key2 = "key2";
74         String JavaDoc value3 = "value";
75
76         configurationContext.setProperty(key1, value1);
77         assertEquals(value1, msgctx.getProperty(key1));
78
79         axisConfiguration.addParameter(new ParameterImpl(key2, value2));
80         assertEquals(value2, msgctx.getProperty(key2));
81
82         opContext.setProperty(key1, value3);
83         assertEquals(value3, msgctx.getProperty(key1));
84
85     }
86
87     public void testDisconntectedHiracy() throws AxisFault {
88         ConfigurationContext configurationContext =
89             new ConfigurationContext(axisConfiguration);
90   
91         MessageContext msgctx =
92             new MessageContext(configurationContext);
93   
94         //test the complte Hisracy built
95
assertEquals(msgctx.getParent(), null);
96
97         String JavaDoc key1 = "key1";
98         String JavaDoc value1 = "Val1";
99         String JavaDoc value2 = "value2";
100         String JavaDoc key2 = "key2";
101         String JavaDoc value3 = "value";
102
103         configurationContext.setProperty(key1, value1);
104         assertEquals(value1, msgctx.getProperty(key1));
105
106         axisConfiguration.addParameter(new ParameterImpl(key2, value2));
107         assertEquals(value2, msgctx.getProperty(key2));
108     }
109
110     protected void tearDown() throws Exception JavaDoc {
111     }
112
113 }
114
Popular Tags