View Javadoc

1   /*
2    * $Id: MtomTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  import java.io.ByteArrayOutputStream;
16  import java.io.File;
17  import java.io.InputStream;
18  import java.net.URL;
19  
20  import javax.activation.DataHandler;
21  import javax.activation.FileDataSource;
22  import javax.xml.ws.BindingProvider;
23  import javax.xml.ws.Holder;
24  import javax.xml.ws.soap.SOAPBinding;
25  
26  import org.apache.cxf.helpers.IOUtils;
27  import org.apache.cxf.mime.TestMtom;
28  import org.apache.cxf.mime.TestMtomService;
29  
30  public class MtomTestCase extends FunctionalTestCase
31  {
32  
33      public void testEchoService() throws Exception
34      {
35          URL wsdl = getClass().getResource("/wsdl/mtom_xop.wsdl");
36          assertNotNull(wsdl);
37          TestMtomService svc = new TestMtomService(wsdl);
38          
39          TestMtom port = svc.getTestMtomPort();
40          
41          BindingProvider bp = ((BindingProvider) port);
42          bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
43              "http://localhost:63081/services/mtom");
44          ((SOAPBinding) bp.getBinding()).setMTOMEnabled(true);
45  //        Client client = ClientProxy.getClient(port);
46  //        new LoggingFeature().initialize(client, null);
47          
48          File file = new File("src/test/resources/mtom-conf.xml");
49          DataHandler dh = new DataHandler(new FileDataSource(file));
50          
51          Holder<String> name = new Holder<String>("test");
52          Holder<DataHandler> info = new Holder<DataHandler>(dh);
53          
54          port.testXop(name, info);
55          
56          assertEquals("return detail + test", name.value);
57          assertNotNull(info.value);
58          
59          InputStream input = info.value.getInputStream();
60          ByteArrayOutputStream bos = new ByteArrayOutputStream();
61          IOUtils.copy(input, bos);
62          input.close();
63      }
64  
65      protected String getConfigResources()
66      {
67          return "mtom-conf.xml";
68      }
69  
70  }
71