From d1eeda291c02a9f74e50106c91d393e36a80f09c Mon Sep 17 00:00:00 2001 From: ramkumar Date: Tue, 10 Feb 2009 10:31:58 +0000 Subject: Fixes for MTOM TestCase git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@742927 13f79535-47bb-0310-9956-ffa450edef68 --- .../ws/axis2/itests/mtom/FileTransferClient.java | 28 +++++-- .../itests/mtom/FileTransferMTOMTestCase.java | 98 ++++++++++++++++++---- .../ws/axis2/itests/mtom/FileTransferService.java | 18 +++- .../itests/mtom/FileTransferServiceClient.java | 41 +++++++++ .../axis2/itests/mtom/FileTransferServiceImpl.java | 46 +++++----- 5 files changed, 186 insertions(+), 45 deletions(-) create mode 100644 branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java (limited to 'branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org') diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java index 82f6ff4c5d..b59a380684 100644 --- a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java +++ b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java @@ -20,17 +20,35 @@ package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; import javax.activation.DataHandler; import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; +import java.awt.Image; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.llom.OMElementImpl; +import javax.xml.transform.Source; /** * This client program shows how to create an SCA runtime, start it, * locate the FileTransfer service and invoke it. */ -public class FileTransferClient implements FileTransferService { +@Service(FileTransferServiceClient.class) +public class FileTransferClient implements FileTransferServiceClient { - @Reference - public FileTransferService fileTransferWS; + @Reference + public FileTransferService fileTransferService; - public String uploadFile(DataHandler attachment) throws Exception { - return fileTransferWS.uploadFile(attachment); + public String uploadImageFileForward (Image attachment) throws Exception { + return fileTransferService.uploadImageFile(attachment); + } + + public String uploadSourceFileForward (Source attachment) throws Exception { + return fileTransferService.uploadSourceFile(attachment); + } + + public String uploadDataHandlerFileForward (DataHandler attachment) throws Exception { + return fileTransferService.uploadDataHandlerFile(attachment); + } + + public String uploadOMElementFileForward (OMElement attachment) throws Exception { + return fileTransferService.uploadOMElementFile(attachment); } } diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java index 69b3b60ea7..a342fa2414 100644 --- a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java +++ b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java @@ -21,34 +21,100 @@ package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; import javax.activation.DataHandler; import javax.activation.FileDataSource; +import java.awt.Image; + +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.llom.OMElementImpl; +import org.apache.axiom.om.OMText; +import javax.xml.transform.dom.DOMSource; +import org.apache.axiom.om.OMFactory; +import java.awt.image.BufferedImage; import junit.framework.TestCase; -import org.apache.tuscany.sca.binding.ws.axis2.itests.mtom.FileTransferService; import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.binding.ws.axis2.itests.mtom.FileTransferServiceClient; +import org.apache.tuscany.sca.databinding.xml.String2Node; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; public class FileTransferMTOMTestCase extends TestCase { private SCADomain domain; + + /** + * Runs once before the tests + */ + @BeforeClass + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite"); + } + + /** + * Runs once after the tests + */ + @AfterClass + protected void tearDown() throws Exception { + domain.close(); + } - public void testFileTransfer() throws Exception { - try { + @Test + public void testImageFileTransfer() throws Exception { + try { + Image image = new BufferedImage(80, 24, BufferedImage.TYPE_INT_RGB); + + FileTransferServiceClient filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent"); + assertEquals("File uploaded Sucessfully", filetransfer.uploadImageFileForward(image)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testSourceFileTransfer() throws Exception { + try { + String xml = "ABC"; + Source source = new DOMSource(new String2Node().transform(xml, null)); + + FileTransferServiceClient filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent"); + assertEquals("File uploaded Sucessfully", filetransfer.uploadSourceFileForward(source)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testDataHandlerFileTransfer() throws Exception { + try { // For testing purpose lets try uploading FileTransferClient.java file. DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE")); - FileTransferService filetransfer = domain.getService(FileTransferService.class, "FileTransferClientComponent"); - //dataHandler.writeTo(System.out); - assertEquals("File uploaded Sucessfully", filetransfer.uploadFile(dataHandler)); + + FileTransferServiceClient filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent"); + assertEquals("File uploaded Sucessfully", filetransfer.uploadDataHandlerFileForward(dataHandler)); } catch (Exception ex){ ex.printStackTrace(); } } - - @Override - protected void setUp() throws Exception { - domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite"); - } - - @Override - protected void tearDown() throws Exception { - domain.close(); + + @Test + public void testOMElementFileTransfer() throws Exception { + try { + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement imageElement = factory.createOMElement(new QName("image")); + + // For testing purpose lets try uploading FileTransferClient.java file. + DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE")); + + OMText textData = factory.createOMText(dataHandler, true); + imageElement.addChild(textData); + + FileTransferServiceClient filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent"); + assertEquals("File uploaded Sucessfully", filetransfer.uploadOMElementFileForward(imageElement)); + + } catch (Exception ex){ + ex.printStackTrace(); + } } - } diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java index ce79b47b86..270c8b5283 100644 --- a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java +++ b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java @@ -20,13 +20,27 @@ package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; import org.osoa.sca.annotations.Remotable; import javax.activation.DataHandler; +import javax.jws.soap.SOAPBinding; + +import java.awt.Image; +import javax.xml.transform.Source; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.axiom.om.OMElement; /** - * This is the business interface of the HelloWorld greetings service. + * This is the business interface of the MTOM FileTransfer service. */ +@SOAPBinding(style = SOAPBinding.Style.DOCUMENT) @Remotable public interface FileTransferService { - public String uploadFile(DataHandler attachment) throws Exception; + public String uploadImageFile(Image attachment) throws Exception; + + public String uploadSourceFile(Source attachment) throws Exception; + + public String uploadDataHandlerFile(DataHandler attachment) throws Exception; + + //@XmlJavaTypeAdapter(value=OMElementXmlAdapter.class) + public String uploadOMElementFile(OMElement attachment) throws Exception; } diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java new file mode 100644 index 0000000000..ca906b1802 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.tuscany.sca.binding.ws.axis2.itests.mtom; + +import javax.activation.DataHandler; +import java.awt.Image; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMElement; + +/** + * This is the client interface of the File Transfer service. + */ +public interface FileTransferServiceClient { + + public String uploadImageFileForward (Image attachment) throws Exception; + + public String uploadSourceFileForward (Source attachment) throws Exception; + + public String uploadDataHandlerFileForward (DataHandler attachment) throws Exception; + + //@XmlJavaTypeAdapter(value=OMElementXmlAdapter.class) + public String uploadOMElementFileForward (OMElement attachment) throws Exception; +} + diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java index 51e31e9f95..57b1a49f19 100644 --- a/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java +++ b/branches/sca-java-1.x/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java @@ -20,33 +20,35 @@ package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; import org.osoa.sca.annotations.Service; import javax.activation.DataHandler; -import java.io.File; -import java.io.FileOutputStream; +import java.awt.Image; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMElement; /** * This class implements the HelloWorld service. */ -@Service(FileTransferService.class) +@Service(interfaces={FileTransferService.class}) public class FileTransferServiceImpl implements FileTransferService { - - public String uploadFile(DataHandler attachment) throws Exception { - - //OMText binaryNode = (OMText) (attachment.getFirstElement()).getFirstOMChild(); - //DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler(); - - // Use this code to save the file we have received. - /*DataHandler dataHandler = attachment; - - File file = new File("transferedfile.java"); - FileOutputStream fileOutputStream = new FileOutputStream(file); - dataHandler.writeTo(fileOutputStream); - fileOutputStream.flush(); - fileOutputStream.close();*/ - - System.out.println("Content type = " + attachment.getContentType() + "\nContent = "); - //attachment.writeTo(System.out); - + + public String uploadImageFile(Image attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String uploadSourceFile(Source attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String uploadDataHandlerFile(DataHandler attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + //@XmlJavaTypeAdapter(value=OMElementXmlAdapter.class) + public String uploadOMElementFile(OMElement attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); return "File uploaded Sucessfully"; } - } -- cgit v1.2.3