axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thil...@apache.org
Subject svn commit: r219179 - /webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
Date Fri, 15 Jul 2005 11:16:59 GMT
Author: thilina
Date: Fri Jul 15 04:16:56 2005
New Revision: 219179

URL: http://svn.apache.org/viewcvs?rev=219179&view=rev
Log:
Commiting the Commons MTOM test


Added:
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
  (with props)

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java?rev=219179&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
(added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
Fri Jul 15 04:16:56 2005
@@ -0,0 +1,164 @@
+/*
+ * 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
+ * 
+ *      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.mtom;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+import java.awt.Image;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.ImageDataSource;
+import org.apache.axis2.attachments.JDK13IO;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class EchoRawMTOMCommonsChunkingTest extends TestCase {
+	private EndpointReference targetEPR = new EndpointReference(
+			AddressingConstants.WSA_TO, "http://127.0.0.1:"
+					+ (UtilServer.TESTING_PORT+1)
+					+ "/axis/services/EchoXMLService/echoOMElement");
+
+	private Log log = LogFactory.getLog(getClass());
+
+	private QName serviceName = new QName("EchoXMLService");
+
+	private QName operationName = new QName("echoOMElement");
+
+	private QName transportName = new QName("http://localhost/my",
+			"NullTransport");
+
+	private String imageInFileName = "img/test.jpg";
+
+	private String imageOutFileName = "mtom/img/testOut.jpg";
+
+	private AxisConfiguration engineRegistry;
+
+	private MessageContext mc;
+
+	private ServiceContext serviceContext;
+
+	private ServiceDescription service;
+	
+	private OMElement data;
+
+	private boolean finish = false;
+
+	public EchoRawMTOMCommonsChunkingTest() {
+		super(EchoRawMTOMCommonsChunkingTest.class.getName());
+	}
+
+	public EchoRawMTOMCommonsChunkingTest(String testName) {
+		super(testName);
+	}
+
+	protected void setUp() throws Exception {
+		UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository");
+		service = Utils.createSimpleService(serviceName, Echo.class.getName(),
+				operationName);
+		UtilServer.deployService(service);
+		serviceContext = UtilServer.getConfigurationContext()
+				.createServiceContext(service.getName());
+	}
+
+	protected void tearDown() throws Exception {
+		UtilServer.unDeployService(serviceName);
+		UtilServer.stop();
+	}
+
+	private OMElement createEnvelope() throws Exception {
+
+		DataHandler expectedDH;
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+		OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs);
+		data = fac.createOMElement("data", omNs);
+		Image expectedImage;
+		expectedImage = new JDK13IO()
+				.loadImage(getResourceAsStream("org/apache/axis2/mtom/test.jpg"));
+
+		ImageDataSource dataSource = new ImageDataSource("test.jpg",
+				expectedImage);
+		expectedDH = new DataHandler(dataSource);
+		//OMTextImpl textData = new OMTextImpl(expectedDH, true);
+		for (int i =0; i<1 ; i++)
+		{
+		OMElement subData = fac.createOMElement("subData",omNs);
+		OMText textData = new OMTextImpl(new DataHandler("Thilina","text/plain"));
+		subData.addChild(textData);
+		data.addChild(subData);
+		}
+		rpcWrapEle.addChild(data);
+		return rpcWrapEle;
+
+	}
+
+	public void testEchoXMLSync() throws Exception {
+		SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+
+		OMElement payload = createEnvelope();
+		
+	   org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(Constants.TESTING_PATH+"commons-http-enabledRepository");
+		call.setTo(targetEPR);
+		call.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+		call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP, Constants.TRANSPORT_HTTP, false);
+
+		OMElement result = (OMElement) call.invokeBlocking(operationName
+				.getLocalPart(), payload);
+
+		OMElement ele = (OMElement) result.getFirstChild();
+		this.campareWithCreatedOMElement(data);
+
+	}
+
+	private InputStream getResourceAsStream(String path) {
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		return cl.getResourceAsStream(path);
+	}
+	
+	private void campareWithCreatedOMElement(OMElement element){
+        OMElement firstChild = element.getFirstElement();
+        TestCase.assertNotNull(firstChild);
+        String originalTextValue = data.getFirstElement().getText();
+        String returnedTextValue = firstChild.getText();    
+        TestCase.assertEquals(returnedTextValue,originalTextValue);
+    }
+
+}
\ No newline at end of file

Propchange: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message