You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by da...@apache.org on 2007/05/26 00:33:47 UTC

svn commit: r541802 - in /webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2: engine/ integration/

Author: davidillsley
Date: Fri May 25 15:33:46 2007
New Revision: 541802

URL: http://svn.apache.org/viewvc?view=rev&rev=541802
Log:
Move more integration tests to the local transport

Modified:
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerExecutionTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceDispatchingTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/UsingTransportTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerExecutionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerExecutionTest.java?view=diff&rev=541802&r1=541801&r2=541802
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerExecutionTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerExecutionTest.java Fri May 25 15:33:46 2007
@@ -1,54 +1,40 @@
 /*
-* Copyright 2006 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 package org.apache.axis2.engine;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.engine.util.FaultThrowingService;
-import org.apache.axis2.engine.util.TestConstants;
 import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.integration.LocalTestCase;
 import org.apache.axis2.integration.TestingUtils;
-import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.integration.UtilServerBasedTestCase;
 import org.apache.axis2.phaseresolver.PhaseMetadata;
-import org.apache.axis2.util.Utils;
 
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class HandlerExecutionTest extends UtilServerBasedTestCase implements
-        TestConstants {
-    private static boolean initDone = false;
+public class HandlerExecutionTest extends LocalTestCase {
     private static ArrayList testResults;
     private AxisService testService;
     private AxisService testFailingService;
@@ -59,18 +45,6 @@
     private TestHandler middleOperationInHandler;
     private TestHandler middleOperationOutHandler;
 
-    public HandlerExecutionTest() {
-        super(HandlerExecutionTest.class.getName());
-    }
-
-    public HandlerExecutionTest(String testName) {
-        super(testName);
-    }
-
-    public static Test suite() {
-        return getTestSetup(new TestSuite(HandlerExecutionTest.class));
-    }
-
     private void registerOperationLevelHandlers(AxisOperation operation) {
         ArrayList operationSpecificPhases = new ArrayList();
         operationSpecificPhases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
@@ -103,12 +77,11 @@
     }
 
     protected void setUp() throws Exception {
+    	super.setUp();
         testResults = new ArrayList();
-        if (!initDone) {
-            initDone = true;
 
             ArrayList globalInPhases =
-                    UtilServer.getConfigurationContext().getAxisConfiguration().getInFlowPhases();
+                    serverConfig.getAxisConfiguration().getInFlowPhases();
             for (int i = 0; i < globalInPhases.size(); i++) {
                 Phase globalInPhase = (Phase)globalInPhases.get(i);
                 if (PhaseMetadata.PHASE_PRE_DISPATCH.equals(globalInPhase.getPhaseName())) {
@@ -118,45 +91,20 @@
                     globalInPhase.addHandler(new TestHandler("In3"));
                 }
             }
-        }
-
         firstOperationInHandler = new TestHandler("In4");
         middleOperationInHandler = new TestHandler("In5");
         middleOperationOutHandler = new TestHandler("Out2");
 
-        testService = Utils.createSimpleService(serviceName,
-                                                Echo.class.getName(),
-                                                operationName);
-        UtilServer.deployService(testService);
-
-        registerOperationLevelHandlers(testService.getOperation(operationName));
-
-        testFailingService = Utils.createSimpleService(failingServiceName,
-                                                       FaultThrowingService.class.getName(),
-                                                       failingOperationName);
-        UtilServer.deployService(testFailingService);
-        registerOperationLevelHandlers(testFailingService.getOperation(failingOperationName));
+        testService = deployClassAsService(Echo.SERVICE_NAME, Echo.class);
+        registerOperationLevelHandlers(testService.getOperation(new QName(Echo.ECHO_OM_ELEMENT_OP_NAME)));
 
-    }
+        testFailingService = deployClassAsService(failingServiceName.getLocalPart(), FaultThrowingService.class);
+        registerOperationLevelHandlers(testFailingService.getOperation(failingOperationName));
 
-    protected void tearDown() throws Exception {
-        UtilServer.unDeployService(serviceName);
-        UtilServer.unDeployService(failingServiceName);
-        UtilServer.unDeployClientService();
     }
 
     private ServiceClient createClient() throws Exception {
-        Options options = new Options();
-        options.setTo(targetEPR);
-        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-
-        ServiceClient sender = new ServiceClient(configContext, null);
-        sender.setOptions(options);
-        return sender;
+    	return getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
     }
 
     private void executeClient() throws Exception {
@@ -220,19 +168,9 @@
         OMElement payload = omFactory.createOMElement("EchoOMElement", null);
         payload.setText(FaultThrowingService.THROW_FAULT_AS_AXIS_FAULT);
 
-        Options options = new Options();
-        options.setTo(new EndpointReference("http://127.0.0.1:" + (UtilServer.TESTING_PORT) +
-                "/axis2/services/" + failingServiceName.getLocalPart() + "/" +
-                failingOperationName.getLocalPart()));
-        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        options.setExceptionToBeThrownOnSOAPFault(false);
-
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-        ServiceClient sender = new ServiceClient(configContext, null);
-        sender.setOptions(options);
-
+        ServiceClient sender = getClient(failingServiceName.getLocalPart(), failingOperationName.getLocalPart());
+        sender.getOptions().setExceptionToBeThrownOnSOAPFault(true);
+        
         AxisOperation operation =
                 sender.getAxisService().getOperation(ServiceClient.ANON_OUT_IN_OP);
         ArrayList operationSpecificPhases = new ArrayList();
@@ -262,12 +200,13 @@
                 operationSpecificPhase.addHandler(new TestHandler("COut3"));
             }
         }
-
-        String result = sender.sendReceive(payload).toString();
-
-        assertTrue(result.indexOf("test:TestFault") > -1);
-        assertTrue(result.indexOf("FaultReason</soapenv:Text>") > -1);
-        assertTrue(result.indexOf("This is a test Exception") > -1);
+        try{
+        	sender.sendReceive(payload);
+        	fail("Expecting exception to be thrown.");
+        }catch(AxisFault af){
+        	assertEquals("TestFault", af.getFaultCode().getLocalPart());
+        	assertTrue(af.getReason().indexOf("FaultReason") > -1);
+        }
         //This odd pattern of CIn FCCIn CIn FCCIn is caused by the InOutAxisOperation always executing the inflow phases, even if there was a fault (and then executing the infaulflow)
         List expectedExecutionState = Arrays.asList(new String[] { "COut1", "COut2", "COut3", "In1",
                 "In2", "In3", "In4", "In5", "In6", "FCIn6", "FCIn5", "FCIn4", "FCIn3", "FCIn2",

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java?view=diff&rev=541802&r1=541801&r2=541802
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java Fri May 25 15:33:46 2007
@@ -1,6 +1,4 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -13,64 +11,43 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.axis2.engine;
 
-//todo
+import java.util.ArrayList;
+
+import javax.xml.namespace.QName;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.util.TestConstants;
 import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.integration.LocalTestCase;
+import org.apache.axis2.integration.TestingUtils;
 import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.integration.UtilServerBasedTestCase;
 import org.apache.axis2.phaseresolver.PhaseMetadata;
-import org.apache.axis2.util.Utils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.util.ArrayList;
 
-
-public class HandlerFailureTest extends UtilServerBasedTestCase implements TestConstants {
+public class HandlerFailureTest extends LocalTestCase {
     private static final Log log = LogFactory.getLog(HandlerFailureTest.class);
 
-    public HandlerFailureTest() {
-        super(HandlerFailureTest.class.getName());
-    }
-
-    public HandlerFailureTest(String testName) {
-        super(testName);
-    }
-
-    public static Test suite() {
-        return getTestSetup(new TestSuite(HandlerFailureTest.class));
-    }
-
-
-    public void testFailureAtServerRequestFlow() throws Exception {
-
-        AxisService service = Utils.createSimpleService(serviceName,
-                                                        Echo.class.getName(),
-                                                        operationName);
-
-        UtilServer.deployService(service);
-        AxisOperation operation = service.getOperation(operationName);
-        ArrayList phasec = new ArrayList();
+    private Handler culprit = new AbstractHandler() {
+        public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+            throw new AxisFault(UtilServer.FAILURE_MESSAGE);
+        }
+    };
+    
+    public void setUp() throws Exception{
+    	super.setUp();
+    	AxisService as = deployClassAsService(Echo.SERVICE_NAME, Echo.class);
+    	AxisOperation operation = as.getOperation(new QName(Echo.ECHO_OM_ELEMENT_OP_NAME));
+    	
+    	ArrayList phasec = new ArrayList();
         phasec.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
         operation.setRemainingPhasesInFlow(phasec);
         ArrayList phase = operation.getRemainingPhasesInFlow();
@@ -80,50 +57,20 @@
                 phase1.addHandler(culprit);
             }
         }
-        try {
-            callTheService();
-        } finally {
-            UtilServer.unDeployService(serviceName);
-        }
     }
 
-    private void callTheService() throws Exception {
+    public void testFailureAtServerRequestFlow() throws Exception {
         try {
-            SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
-
-            OMNamespace omNs = fac.createOMNamespace("http://localhost/my",
-                                                     "my");
-            OMElement method = fac.createOMElement("echoOMElement", omNs);
-            OMElement value = fac.createOMElement("myValue", omNs);
-            value.setText("Isaac Asimov, The Foundation Trilogy");
-            method.addChild(value);
-            Options options = new Options();
-            options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-            options.setTo(targetEPR);
-            ConfigurationContext configContext =
-                    ConfigurationContextFactory
-                            .createConfigurationContextFromFileSystem(null, null);
-            ServiceClient sender = new ServiceClient(configContext, null);
-            sender.setOptions(options);
-
-            OMElement result = sender.sendReceive(method);
-
-
-            result.serializeAndConsume(StAXUtils.createXMLStreamWriter(
-                    System.out));
+            ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+            
+            OMElement result = sender.sendReceive(TestingUtils.createDummyOMElement());
+            result.serializeAndConsume(StAXUtils.createXMLStreamWriter(System.out));
             fail("the test must fail due to the intentional failure of the \"culprit\" handler");
         } catch (AxisFault e) {
             log.info(e.getMessage());
             String message = e.getMessage();
             assertTrue((message.indexOf(UtilServer.FAILURE_MESSAGE)) >= 0);
         }
-
     }
-
-    private Handler culprit = new AbstractHandler() {
-        public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
-            throw new AxisFault(UtilServer.FAILURE_MESSAGE);
-        }
-    };
 }
 

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceDispatchingTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceDispatchingTest.java?view=diff&rev=541802&r1=541801&r2=541802
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceDispatchingTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceDispatchingTest.java Fri May 25 15:33:46 2007
@@ -1,6 +1,4 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -16,109 +14,50 @@
 
 package org.apache.axis2.engine;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.dispatchers.RequestURIBasedOperationDispatcher;
+import org.apache.axis2.integration.LocalTestCase;
 import org.apache.axis2.integration.TestingUtils;
-import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.integration.UtilServerBasedTestCase;
-import org.apache.axis2.util.Utils;
-
-public class ServiceDispatchingTest extends UtilServerBasedTestCase implements TestConstants {
-    public ServiceDispatchingTest() {
-        super(ServiceDispatchingTest.class.getName());
-    }
-
-    public ServiceDispatchingTest(String testName) {
-        super(testName);
-    }
 
-    public static Test suite() {
-        return getTestSetup(new TestSuite(ServiceDispatchingTest.class));
-    }
+public class ServiceDispatchingTest extends LocalTestCase {
 
     protected void setUp() throws Exception {
-        AxisService service = Utils.createSimpleService(serviceName,
-                                                        Echo.class.getName(),
-                                                        operationName);
-        UtilServer.deployService(service);
-
-    }
-
-    protected void tearDown() throws Exception {
-        UtilServer.unDeployService(serviceName);
-        UtilServer.unDeployClientService();
+    	super.setUp();
+    	deployClassAsService(Echo.SERVICE_NAME, Echo.class);
     }
 
-
     public void testDispatchWithURLOnly() throws Exception {
-        OMElement payload = TestingUtils.createDummyOMElement();
-        Options options = new Options();
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-        ServiceClient sender = new ServiceClient(configContext, null);
-        sender.setOptions(options);
-        options.setTo(targetEPR);
+    	DispatchPhase dp = new DispatchPhase();
+    	dp.addHandler(new RequestURIBasedDispatcher());
+    	dp.addHandler(new RequestURIBasedOperationDispatcher());
+    	serverConfig.getInFlowPhases().set(1, dp);
+    	
+        ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+        String oldAddress = sender.getOptions().getTo().getAddress();
+        String newAddress = oldAddress+"/"+Echo.ECHO_OM_ELEMENT_OP_NAME;
+        sender.getOptions().getTo().setAddress(newAddress);
+        sender.getOptions().setAction(null);
 
-        OMElement result = sender.sendReceive(payload);
+        OMElement result = sender.sendReceive(TestingUtils.createDummyOMElement());
 
         TestingUtils.compareWithCreatedOMElement(result);
     }
 
     public void testDispatchWithURLAndSOAPAction() throws Exception {
-        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
-        OMNamespace omNs = fac.createOMNamespace("http://dummyURL", "my");
-        OMElement payload = fac.createOMElement("echoOMElementRequest", omNs);
-        OMElement value = fac.createOMElement("myValue", omNs);
-        value.addChild(
-                fac.createOMText(value, "Isaac Asimov, The Foundation Trilogy"));
-        payload.addChild(value);
-        Options options = new Options();
-        options.setTo(
-                new EndpointReference("http://127.0.0.1:5555/axis2/services/EchoXMLService/"));
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        options.setAction("echoOMElement");
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-        ServiceClient sender = new ServiceClient(configContext, null);
-        sender.setOptions(options);
-
-        OMElement result = sender.sendReceive(payload);
+        ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+        OMElement result = sender.sendReceive(TestingUtils.createDummyOMElement());
         TestingUtils.compareWithCreatedOMElement(result);
     }
 
     public void testDispatchWithSOAPBody() throws Exception {
-        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
-
-        OMNamespace omNs = fac.createOMNamespace(
-                "http://127.0.0.1:5555/axis2/services/EchoXMLService", "my");
-        OMElement payload = fac.createOMElement("echoOMElement", omNs);
-        OMElement value = fac.createOMElement("myValue", omNs);
-        value.addChild(
-                fac.createOMText(value, "Isaac Asimov, The Foundation Trilogy"));
-        payload.addChild(value);
-        Options options = new Options();
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-        ServiceClient sender = new ServiceClient(configContext, null);
-        sender.setOptions(options);
-        options.setTo(targetEPR);
-
+    	DispatchPhase dp = new DispatchPhase();
+    	dp.addHandler(new SOAPMessageBodyBasedDispatcher());
+    	serverConfig.getInFlowPhases().set(1, dp);
+    	
+    	ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+    	OMElement payload = TestingUtils.createDummyOMElement(sender.getOptions().getTo().getAddress());
         OMElement result = sender.sendReceive(payload);
-
         TestingUtils.compareWithCreatedOMElement(result);
     }
 }

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/UsingTransportTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/UsingTransportTest.java?view=diff&rev=541802&r1=541801&r2=541802
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/UsingTransportTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/UsingTransportTest.java Fri May 25 15:33:46 2007
@@ -1,6 +1,4 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -13,180 +11,51 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.axis2.engine;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.OperationClient;
-import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.util.TestConstants;
-import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.integration.UtilServerBasedTestCase;
-import org.apache.axis2.util.Utils;
+import org.apache.axis2.integration.LocalTestCase;
+import org.apache.axis2.integration.TestingUtils;
 import org.apache.axis2.wsdl.WSDLConstants;
 
-import javax.xml.namespace.QName;
-
-
-public class UsingTransportTest extends UtilServerBasedTestCase implements TestConstants {
-
-    QName assumedServiceName = new QName("AnonymousService");
-
-
-    private AxisService service = null;
-
-
-    public static Test suite() {
-        return getTestSetup(new TestSuite(UsingTransportTest.class));
-    }
+public class UsingTransportTest extends LocalTestCase {
 
     protected void setUp() throws Exception {
-        service = Utils.createSimpleService(TestConstants.serviceName, Echo.class.getName(),
-                                            TestConstants.operationName);
-        UtilServer.deployService(service);
+        super.setUp();
+        deployClassAsService(Echo.SERVICE_NAME, Echo.class);
     }
 
-    protected void tearDown() throws Exception {
-        UtilServer.unDeployService(TestConstants.serviceName);
-        UtilServer.unDeployClientService();
-    }
-
-
-    public void testValidTransport() throws AxisFault {
-        String title = "testValidTransport(): ";
-
-        OMElement payload = createEnvelope();
-
-        ConfigurationContext configCtx =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-
-        ServiceClient servClient = new ServiceClient(configCtx, null);
-
-        Options options = new Options();
-        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-        options.setTo(targetEPR);
-        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        servClient.setOptions(options);
-
-        OperationClient opClinet = servClient.createClient(ServiceClient.ANON_OUT_IN_OP);
-        String ocType = opClinet.getClass().getName();
-        System.out.println("\n" + title + "Using OperationClient [" + ocType + "]");
-        opClinet.addMessageContext(prepareTheSOAPEnvelope(payload, options));
-        System.out.println(title + "Invoking OperationClient [" + ocType + "] execute()");
-        opClinet.execute(true);
-
-        SOAPEnvelope result =
-                opClinet.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();
-
-        assertEquals("SOAP Version received is not compatible",
-                     SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,
-                     result.getNamespace().getNamespaceURI());
+    public void testSOAPVersioning() throws Exception{
+    	ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+    	sender.getOptions().setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+    	sender.setCachingOperationContext(true);
+    	OMElement response = sender.sendReceive(TestingUtils.createDummyOMElement());
+    	TestingUtils.compareWithCreatedOMElement(response);
+    	SOAPEnvelope result =
+            sender.getLastOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();
+    	 assertEquals("SOAP Version received is not compatible",
+                 SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,
+                 result.getNamespace().getNamespaceURI());
     }
-
-
+    
+    // The valid case is covered by loads of other tests...
     public void testInvalidTransport() throws AxisFault {
-        String title = "testInvalidTransport(): ";
-        OMElement payload = createEnvelope();
-
-        ConfigurationContext configCtx =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
-
-        ServiceClient servClient = new ServiceClient(configCtx, null);
-
-        Options options = new Options();
-        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
-        // set the endpoint with "htp" instead of "http" 
-        EndpointReference invalidTargetEPR = new EndpointReference(
-                "htp://127.0.0.1:5556/axis2/services/EchoXMLService/echoOMElement");
-        options.setTo(invalidTargetEPR);
-
-        servClient.setOptions(options);
-
-        OperationClient opClinet = servClient.createClient(ServiceClient.ANON_OUT_IN_OP);
-        String ocType = opClinet.getClass().getName();
-        System.out.println(title + "Using OperationClient [" + ocType + "]");
-
-        MessageContext msgCtx = prepareTheSOAPEnvelope(payload, options);
-
-        opClinet.addMessageContext(msgCtx);
-
-        try {
-            System.out.println(title + "Invoking OperationClient [" + ocType + "] execute()");
-            opClinet.execute(true);
+    	ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
+    	String oldAddress = sender.getOptions().getTo().getAddress();
+    	String newAddress = "lcl"+oldAddress.substring(5);
+    	sender.getOptions().getTo().setAddress(newAddress);
+    	sender.getOptions().setTransportOut(null);
+    	try {
+            sender.sendReceive(TestingUtils.createDummyOMElement());
+            fail("Expecting a failure - shouldn't be able to determine the out transport from 'lcl'");
         }
         catch (Exception ex) {
-            String exName = ex.getClass().getName();
-
-            System.out.println(title +
-                    "Expecting an exception of type [org.apache.axis2.AxisFault].   Caught exception  [" +
-                    exName + "]    error [" + ex.getMessage() + "]");
-            ex.printStackTrace();
-
             assertTrue("Expecting an exception of type [org.apache.axis2.AxisFault]",
                        (ex instanceof org.apache.axis2.AxisFault));
         }
-
-    }
-
-
-    private MessageContext prepareTheSOAPEnvelope(OMElement toSend, Options options)
-            throws AxisFault {
-        MessageContext msgctx = new MessageContext();
-
-        SOAPFactory sf = getSOAPFactory(options);
-        SOAPEnvelope se = sf.getDefaultEnvelope();
-
-        if (toSend != null) {
-            se.getBody().addChild(toSend);
-        }
-
-        msgctx.setEnvelope(se);
-        return msgctx;
     }
-
-
-    private SOAPFactory getSOAPFactory(Options options) {
-        String soapVersionURI = options.getSoapVersionURI();
-
-        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
-            return OMAbstractFactory.getSOAP12Factory();
-        } else {
-            // if its not SOAP 1.2 just assume SOAP 1.1
-            return OMAbstractFactory.getSOAP11Factory();
-        }
-    }
-
-
-    private OMElement createEnvelope() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
-
-        OMElement method = fac.createOMElement("echoOMElement", omNs);
-
-        OMElement value = fac.createOMElement("myValue", omNs);
-        value.addChild(fac.createOMText(value, "Isaac Asimov, The Foundation Trilogy"));
-
-        method.addChild(value);
-
-        return method;
-    }
-
-
 }

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java?view=diff&rev=541802&r1=541801&r2=541802
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java Fri May 25 15:33:46 2007
@@ -13,19 +13,18 @@
  */
 package org.apache.axis2.integration;
 
+import java.util.ArrayList;
+
 import junit.framework.TestCase;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
-import org.apache.axis2.rpc.client.RPCServiceClient;
-import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
-import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.deployment.util.Utils;
-import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.description.WSDL2Constants;
@@ -33,10 +32,11 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.DispatchPhase;
 import org.apache.axis2.engine.Phase;
+import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.axis2.rpc.client.RPCServiceClient;
 import org.apache.axis2.transport.local.LocalTransportReceiver;
 import org.apache.axis2.transport.local.LocalTransportSender;
-
-import java.util.ArrayList;
 
 /**
  * LocalTestCase is an extendable base class which provides common functionality



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org