1 7 8 package test.wsdl.interop4.groupG.dime.doc; 9 10 import java.net.URL ; 11 import java.util.Arrays ; 12 import java.io.InputStream ; 13 import java.io.IOException ; 14 import java.io.OutputStream ; 15 import java.io.ByteArrayInputStream ; 16 17 import org.apache.axis.attachments.OctetStream; 18 import org.apache.axis.client.Call; 19 20 import javax.activation.DataSource ; 21 import javax.activation.DataHandler ; 22 23 public class DimeDOCInteropTestCase extends junit.framework.TestCase { 24 public DimeDOCInteropTestCase(java.lang.String name) { 25 super(name); 26 } 27 28 public void testDimeDOCSoapPortWSDL() throws Exception { 29 javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance(); 30 java.net.URL url = new java.net.URL (new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPortAddress() + "?WSDL"); 31 javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getServiceName()); 32 assertTrue(service != null); 33 } 34 35 protected void setUp() throws Exception { 36 if(url == null) { 37 url = new URL (new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPortAddress()); 38 } 39 } 40 public void test1DimeDOCSoapPortEchoAttachment() throws Exception { 41 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 42 try { 43 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 44 } 45 catch (javax.xml.rpc.ServiceException jre) { 46 if(jre.getLinkedCause()!=null) 47 jre.getLinkedCause().printStackTrace(); 48 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 49 } 50 assertTrue("binding is null", binding != null); 51 52 OctetStream input = new OctetStream("EchoAttachment".getBytes()); 54 OctetStream output = null; 55 output = binding.echoAttachment(input); 56 assertTrue(Arrays.equals(input.getBytes(), output.getBytes())); 58 } 59 60 public void test2DimeDOCSoapPortEchoAttachments() throws Exception { 61 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 62 try { 63 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 64 } 65 catch (javax.xml.rpc.ServiceException jre) { 66 if(jre.getLinkedCause()!=null) 67 jre.getLinkedCause().printStackTrace(); 68 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 69 } 70 assertTrue("binding is null", binding != null); 71 72 OctetStream[] input = new OctetStream[2]; 73 74 input[0] = new OctetStream("EchoAttachments0".getBytes()); 75 input[1] = new OctetStream("EchoAttachments1".getBytes()); 76 77 OctetStream[] output = null; 79 output = binding.echoAttachments(input); 80 assertTrue(Arrays.equals(input[0].getBytes(), output[0].getBytes())); 82 assertTrue(Arrays.equals(input[1].getBytes(), output[1].getBytes())); 83 } 84 85 public void test3DimeDOCSoapPortEchoAttachmentAsBase64() throws Exception { 86 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 87 try { 88 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 89 } 90 catch (javax.xml.rpc.ServiceException jre) { 91 if(jre.getLinkedCause()!=null) 92 jre.getLinkedCause().printStackTrace(); 93 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 94 } 95 assertTrue("binding is null", binding != null); 96 97 OctetStream input = new OctetStream("EchoAttachmentAsBase64".getBytes()); 98 byte[] output = null; 100 output = binding.echoAttachmentAsBase64(input); 101 assertTrue(Arrays.equals(input.getBytes(), output)); 103 } 104 105 public void test4DimeDOCSoapPortEchoBase64AsAttachment() throws Exception { 106 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 107 try { 108 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 109 } 110 catch (javax.xml.rpc.ServiceException jre) { 111 if(jre.getLinkedCause()!=null) 112 jre.getLinkedCause().printStackTrace(); 113 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 114 } 115 assertTrue("binding is null", binding != null); 116 117 byte[] input = "EchoBase64AsAttachment".getBytes(); 118 OctetStream output = null; 120 output = binding.echoBase64AsAttachment(input); 121 assertTrue(Arrays.equals(input, output.getBytes())); 123 } 124 125 public void test5DimeDOCSoapPortEchoUnrefAttachments() throws Exception { 126 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 127 try { 128 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 129 } 130 catch (javax.xml.rpc.ServiceException jre) { 131 if(jre.getLinkedCause()!=null) 132 jre.getLinkedCause().printStackTrace(); 133 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 134 } 135 assertTrue("binding is null", binding != null); 136 137 class Src implements DataSource { 138 InputStream m_src; 139 String m_type; 140 141 public Src(InputStream data, String type){ 142 m_src=data; 143 m_type=type; 144 } 145 public String getContentType(){ 146 return m_type; 147 } 148 public InputStream getInputStream() throws IOException { 149 m_src.reset(); 150 return m_src; 151 } 152 public String getName(){ 153 return "Some-Data"; 154 } 155 public OutputStream getOutputStream(){ 156 throw new UnsupportedOperationException ("I don't give output streams"); 157 } 158 } 159 ByteArrayInputStream ins=new ByteArrayInputStream ("EchoUnrefAttachments".getBytes()); 160 DataHandler dh=new DataHandler (new Src(ins,"application/octetstream")); 161 162 163 ((org.apache.axis.client.Stub)binding).addAttachment(dh); 164 ((org.apache.axis.client.Stub)binding)._setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME); 165 binding.echoUnrefAttachments(); 167 Object attachments[] = ((org.apache.axis.client.Stub)binding).getAttachments(); 169 assertEquals(1, attachments.length); 170 } 171 172 public void test6DimeDOCSoapPortEchoAttachmentAsString() throws Exception { 173 test.wsdl.interop4.groupG.dime.doc.AttachmentsPortType binding; 174 try { 175 binding = new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPort(url); 176 } 177 catch (javax.xml.rpc.ServiceException jre) { 178 if(jre.getLinkedCause()!=null) 179 jre.getLinkedCause().printStackTrace(); 180 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 181 } 182 assertTrue("binding is null", binding != null); 183 184 java.lang.String input = "EchoAttachmentAsString"; 185 186 java.lang.String output = null; 188 output = binding.echoAttachmentAsString(input); 189 assertEquals(input, output); 191 } 192 193 public static URL url = null; 194 195 public static void main(String [] args) throws Exception { 196 if (args.length == 1) { 197 url = new URL (args[0]); 198 } else { 199 url = new URL (new test.wsdl.interop4.groupG.dime.doc.DimeDOCInteropLocator().getDimeDOCSoapPortAddress()); 200 } 201 junit.textui.TestRunner.run(new junit.framework.TestSuite(DimeDOCInteropTestCase.class)); 202 } } 204 | Popular Tags |