summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java
blob: 35bf6888e30136dfe0da54221f07f6cf8af27db0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * 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 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.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.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;
    private FileTransferServiceClient filetransfer;
    
    /**
     * 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");
    	filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent");
    }
   
    /**
     * Runs once after the tests
     */
    @AfterClass
    protected void tearDown() throws Exception {
    	domain.close();
    }

    @Test
    public void testImageFileTransfer() throws Exception {
        try {        	
            Image image = new BufferedImage(80, 24, BufferedImage.TYPE_INT_RGB);
            assertEquals("File uploaded Sucessfully", filetransfer.uploadImageFileForward(image));            
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    @Test
    public void testSourceFileTransfer() throws Exception {
        try {        	 
        	String xml = "<a>A<b>B</b><c>C</c></a>";
            Source source = new DOMSource(new String2Node().transform(xml, null));
            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 LICENSE file.
            DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE"));
            assertEquals("File uploaded Sucessfully", filetransfer.uploadDataHandlerFileForward(dataHandler));            
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    @Test
    public void testOMElementFileTransfer() throws Exception {
        try {        	
        	OMFactory factory = OMAbstractFactory.getOMFactory();                        
            OMElement imageElement = factory.createOMElement(new QName("image"));          
            
            DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE"));
            
            OMText textData = factory.createOMText(dataHandler, true);
            imageElement.addChild(textData);
            assertEquals("File uploaded Sucessfully", filetransfer.uploadOMElementFileForward(imageElement));
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    @Test
    public void testSendMyException() throws Exception {
        try {        	
            MyException exp = new MyExceptionImpl();
            assertEquals("File uploaded Sucessfully", filetransfer.sendMyExceptionForward(exp));            
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
}