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:
020: package org.apache.axis2.context;
021:
022: import junit.framework.TestCase;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.description.AxisOperation;
025: import org.apache.axis2.description.AxisService;
026: import org.apache.axis2.description.InOutAxisOperation;
027: import org.apache.axis2.description.Parameter;
028: import org.apache.axis2.engine.AxisConfiguration;
029:
030: import javax.xml.namespace.QName;
031:
032: public class ContextHierarchyTest extends TestCase {
033: private AxisOperation axisOperation;
034: private AxisService axisService;
035: private AxisConfiguration axisConfiguration;
036: private ConfigurationContext configurationContext;
037: private MessageContext msgctx;
038:
039: protected void setUp() throws Exception {
040: axisOperation = new InOutAxisOperation(new QName("Temp"));
041: axisService = new AxisService("Temp");
042: axisConfiguration = new AxisConfiguration();
043: axisService.addOperation(axisOperation);
044: axisConfiguration.addService(axisService);
045: configurationContext = new ConfigurationContext(
046: axisConfiguration);
047: msgctx = configurationContext.createMessageContext();
048: }
049:
050: public void testCompleteHierarchy() throws AxisFault {
051: ServiceGroupContext serviceGroupContext = configurationContext
052: .createServiceGroupContext(axisService
053: .getAxisServiceGroup());
054: ServiceContext serviceContext = serviceGroupContext
055: .getServiceContext(axisService);
056: OperationContext opContext = axisOperation
057: .findOperationContext(msgctx, serviceContext);
058: axisOperation.registerOperationContext(msgctx, opContext);
059: msgctx.setServiceContext(serviceContext);
060:
061: // test the complte Hierarchy built
062: assertEquals(msgctx.getParent(), opContext);
063: assertEquals(opContext.getParent(), serviceContext);
064: assertEquals(serviceContext.getParent(), serviceGroupContext);
065:
066: String key1 = "key1";
067: String value1 = "Val1";
068: String value2 = "value2";
069: String key2 = "key2";
070: String value3 = "value";
071: String key3 = "key3";
072:
073: configurationContext.setProperty(key1, value1);
074: assertEquals(value1, msgctx.getProperty(key1));
075:
076: axisConfiguration.addParameter(new Parameter(key2, value2));
077: assertEquals(value2, msgctx.getParameter(key2).getValue());
078:
079: opContext.setProperty(key1, value3);
080: assertEquals(value3, msgctx.getProperty(key1));
081:
082: serviceContext.setProperty(key3, value3);
083: assertEquals(value3, msgctx.getProperty(key3));
084: }
085:
086: public void testDisconntectedHierarchy() throws AxisFault {
087: // test the complete Hierarchy built
088: assertEquals(msgctx.getParent(), null);
089:
090: String key1 = "key1";
091: String value1 = "Val1";
092: String value2 = "value2";
093: String key2 = "key2";
094:
095: configurationContext.setProperty(key1, value1);
096: assertEquals(value1, msgctx.getProperty(key1));
097:
098: axisConfiguration.addParameter(new Parameter(key2, value2));
099: assertEquals(value2, msgctx.getParameter(key2).getValue());
100: }
101: }
|