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.synapse.samples.n2n;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.synapse.ServerManager;
024: import org.apache.axis2.engine.ListenerManager;
025: import org.custommonkey.xmlunit.NamespaceContext;
026: import org.custommonkey.xmlunit.SimpleNamespaceContext;
027: import org.custommonkey.xmlunit.XMLTestCase;
028: import org.custommonkey.xmlunit.XMLUnit;
029: import samples.util.SampleAxis2Server;
030: import samples.util.SampleAxis2ServerManager;
031:
032: import java.io.ByteArrayOutputStream;
033: import java.io.OutputStream;
034: import java.util.HashMap;
035: import java.util.Map;
036:
037: /**
038: *
039: */
040: public abstract class AbstractAutomationTestCase extends XMLTestCase {
041:
042: protected void setUp() throws java.lang.Exception {
043: super .setUp();
044: SampleAxis2Server
045: .main(new String[] {
046: "-repo",
047: "modules/samples/target/test_repos/axis2Server/",
048: "-conf",
049: "modules/samples/target/test_repos/axis2Server/conf/axis2.xml" });
050: System.setProperty("repository",
051: "modules/samples/target/test_repos/axis2Client");
052: setUpSynapseEnv();
053: setUpNSContext();
054: }
055:
056: protected void setUpSynapseEnv() {
057: System.setProperty("port", "8080");
058: System
059: .setProperty(
060: "org.apache.xerces.xni.parser.XMLParserConfiguration",
061: "org.apache.xerces.parsers.XMLGrammarCachingConfiguration");
062: System
063: .setProperty("axis2.xml",
064: "modules/samples/target/test_repos/synapse/conf/axis2.xml");
065: ServerManager.getInstance().setAxis2Repolocation(SYNAPSE_REPO);
066: ServerManager.getInstance().start();
067: }
068:
069: protected void setUpNSContext() {
070: Map m = new HashMap();
071: m.put("ms", "http://services.samples/xsd");
072: m.put("ns", "http://services.samples/xsd");
073: NamespaceContext nsCtx = new SimpleNamespaceContext(m);
074: XMLUnit.setXpathNamespaceContext(nsCtx);
075: }
076:
077: protected String getStringResultOfTest(OMElement elem)
078: throws Exception {
079: OutputStream os = new ByteArrayOutputStream();
080: elem.serialize(os);
081: return os.toString();
082: }
083:
084: protected void startCustomAxis2Server(String httpPort,
085: String httpsPort) throws Exception {
086: System.setProperty("http_port", httpPort);
087: System.setProperty("https_port", httpsPort);
088: SampleAxis2ServerManager
089: .getInstance()
090: .start(
091: new String[] {
092: "-repo",
093: "modules/samples/target/test_repos/axis2Server/",
094: "-conf",
095: "modules/samples/target/test_repos/axis2Server/conf/axis2.xml" });
096: }
097:
098: protected void stopCustomAxis2Server(String httpPort,
099: String httpsPort) throws Exception {
100: SampleAxis2ServerManager.getInstance().stop();
101: }
102:
103: protected void tearDown() throws Exception {
104: ServerManager.getInstance().stop();
105: super .tearDown();
106: }
107:
108: protected final String SYNAPSE_REPO = "modules/samples/target/test_repos/synapse";
109: protected final String SAMPLE_CONFIG_ROOT_PATH = "repository/conf/sample/";
110: protected final String SYNAPSE_BASE_URL = "http://localhost:8080/";
111: }
|