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