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.engine;
021:
022: import junit.framework.TestCase;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.AbstractTestCase;
025: import org.apache.axis2.context.ConfigurationContext;
026: import org.apache.axis2.context.ConfigurationContextFactory;
027: import org.apache.axis2.deployment.DeploymentException;
028: import org.apache.axis2.deployment.ServiceBuilder;
029: import org.apache.axis2.description.AxisOperation;
030: import org.apache.axis2.description.AxisService;
031: import org.apache.axis2.description.ModuleConfiguration;
032: import org.apache.axis2.description.Parameter;
033:
034: import javax.xml.namespace.QName;
035: import javax.xml.stream.XMLStreamException;
036: import java.io.FileInputStream;
037: import java.io.FileNotFoundException;
038: import java.io.InputStream;
039:
040: public class ModuleConfigTest extends TestCase {
041:
042: AxisConfiguration ar;
043: String axis2xml = AbstractTestCase.basedir
044: + "/target/test-resources/deployment/moduleConfig/axis2.xml";
045: String repo = AbstractTestCase.basedir
046: + "/target/test-resources/deployment/moduleConfig";
047:
048: public void testModuleConfigAtAxisConfig() {
049: try {
050: ar = ConfigurationContextFactory
051: .createConfigurationContextFromFileSystem(null,
052: axis2xml).getAxisConfiguration();
053: ModuleConfiguration moduleConfiguration = ar
054: .getModuleConfig("testModule");
055: assertNotNull(moduleConfiguration);
056: Parameter para = moduleConfiguration
057: .getParameter("testModulePara");
058: assertNotNull(para);
059:
060: moduleConfiguration = ar.getModuleConfig("testModule2");
061: assertNotNull(moduleConfiguration);
062: para = moduleConfiguration.getParameter("testModulePara2");
063: assertNotNull(para);
064: } catch (AxisFault e) {
065: fail("This can not fail with this DeploymentException " + e);
066: }
067: }
068:
069: public void testModuleConfigAtService() {
070: try {
071: ConfigurationContext configurationContext = ConfigurationContextFactory
072: .createConfigurationContextFromFileSystem(null,
073: axis2xml);
074: ar = configurationContext.getAxisConfiguration();
075:
076: AxisService service = new AxisService();
077: service.setName("testService");
078: ar.addService(service);
079: InputStream in = new FileInputStream(repo + "/service1.xml");
080: ServiceBuilder sbuilder = new ServiceBuilder(in,
081: configurationContext, service);
082: sbuilder.populateService(sbuilder.buildOM());
083:
084: ModuleConfiguration moduleConfiguration = service
085: .getModuleConfig("Servie_module");
086: assertNotNull(moduleConfiguration);
087: Parameter para = moduleConfiguration
088: .getParameter("Servie_module_para");
089: assertNotNull(para);
090:
091: AxisOperation op = service.getOperation(new QName(
092: "echoString"));
093: assertNotNull(op);
094:
095: moduleConfiguration = op.getModuleConfig("Op_Module");
096: assertNotNull(moduleConfiguration);
097: para = moduleConfiguration.getParameter("Op_Module_para");
098: assertNotNull(para);
099:
100: } catch (DeploymentException e) {
101: fail("This can not fail with this DeploymentException " + e);
102: } catch (FileNotFoundException e) {
103: fail("This can not fail with this FileNotFoundException "
104: + e);
105: } catch (AxisFault axisFault) {
106: fail("This can not fail with this AxisFault " + axisFault);
107: } catch (XMLStreamException e) {
108: fail("This can not fail with this AxisFault " + e);
109: }
110: }
111: }
|